From 8537ddf8a67b0ecda1d87f51ca25379a2c30c173 Mon Sep 17 00:00:00 2001 From: neuecc Date: Tue, 22 Sep 2020 09:54:05 +0900 Subject: [PATCH] fix Forget when source is already completed and source is manualy optimized task source, does not work correctly --- .../UniTask/Runtime/UniTaskExtensions.cs | 56 ++++++++++--------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTaskExtensions.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTaskExtensions.cs index 8664f03..aed4a17 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTaskExtensions.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTaskExtensions.cs @@ -561,21 +561,23 @@ namespace Cysharp.Threading.Tasks UniTaskScheduler.PublishUnobservedTaskException(ex); } } - - awaiter.SourceOnCompleted(state => + else { - using (var t = (StateTuple)state) + awaiter.SourceOnCompleted(state => { - try + using (var t = (StateTuple)state) { - t.Item1.GetResult(); + try + { + t.Item1.GetResult(); + } + catch (Exception ex) + { + UniTaskScheduler.PublishUnobservedTaskException(ex); + } } - catch (Exception ex) - { - UniTaskScheduler.PublishUnobservedTaskException(ex); - } - } - }, StateTuple.Create(awaiter)); + }, StateTuple.Create(awaiter)); + } } public static void Forget(this UniTask task, Action exceptionHandler, bool handleExceptionOnMainThread = true) @@ -629,21 +631,23 @@ namespace Cysharp.Threading.Tasks UniTaskScheduler.PublishUnobservedTaskException(ex); } } - - awaiter.SourceOnCompleted(state => + else { - using (var t = (StateTuple.Awaiter>)state) + awaiter.SourceOnCompleted(state => { - try + using (var t = (StateTuple.Awaiter>)state) { - t.Item1.GetResult(); + try + { + t.Item1.GetResult(); + } + catch (Exception ex) + { + UniTaskScheduler.PublishUnobservedTaskException(ex); + } } - catch (Exception ex) - { - UniTaskScheduler.PublishUnobservedTaskException(ex); - } - } - }, StateTuple.Create(awaiter)); + }, StateTuple.Create(awaiter)); + } } public static void Forget(this UniTask task, Action exceptionHandler, bool handleExceptionOnMainThread = true) @@ -736,12 +740,12 @@ namespace Cysharp.Threading.Tasks { await await task; } - + public static async UniTask Unwrap(this Task> task) { return await await task; } - + public static async UniTask Unwrap(this Task> task, bool continueOnCapturedContext) { return await await task.ConfigureAwait(continueOnCapturedContext); @@ -756,12 +760,12 @@ namespace Cysharp.Threading.Tasks { await await task.ConfigureAwait(continueOnCapturedContext); } - + public static async UniTask Unwrap(this UniTask> task) { return await await task; } - + public static async UniTask Unwrap(this UniTask> task, bool continueOnCapturedContext) { return await (await task).ConfigureAwait(continueOnCapturedContext);