fix Forget when source is already completed and source is manualy optimized task source, does not work correctly

master
neuecc 2020-09-22 09:54:05 +09:00
parent 346b1e0a6b
commit 8537ddf8a6
1 changed files with 30 additions and 26 deletions

View File

@ -561,21 +561,23 @@ namespace Cysharp.Threading.Tasks
UniTaskScheduler.PublishUnobservedTaskException(ex); UniTaskScheduler.PublishUnobservedTaskException(ex);
} }
} }
else
awaiter.SourceOnCompleted(state =>
{ {
using (var t = (StateTuple<UniTask.Awaiter>)state) awaiter.SourceOnCompleted(state =>
{ {
try using (var t = (StateTuple<UniTask.Awaiter>)state)
{ {
t.Item1.GetResult(); try
{
t.Item1.GetResult();
}
catch (Exception ex)
{
UniTaskScheduler.PublishUnobservedTaskException(ex);
}
} }
catch (Exception ex) }, StateTuple.Create(awaiter));
{ }
UniTaskScheduler.PublishUnobservedTaskException(ex);
}
}
}, StateTuple.Create(awaiter));
} }
public static void Forget(this UniTask task, Action<Exception> exceptionHandler, bool handleExceptionOnMainThread = true) public static void Forget(this UniTask task, Action<Exception> exceptionHandler, bool handleExceptionOnMainThread = true)
@ -629,21 +631,23 @@ namespace Cysharp.Threading.Tasks
UniTaskScheduler.PublishUnobservedTaskException(ex); UniTaskScheduler.PublishUnobservedTaskException(ex);
} }
} }
else
awaiter.SourceOnCompleted(state =>
{ {
using (var t = (StateTuple<UniTask<T>.Awaiter>)state) awaiter.SourceOnCompleted(state =>
{ {
try using (var t = (StateTuple<UniTask<T>.Awaiter>)state)
{ {
t.Item1.GetResult(); try
{
t.Item1.GetResult();
}
catch (Exception ex)
{
UniTaskScheduler.PublishUnobservedTaskException(ex);
}
} }
catch (Exception ex) }, StateTuple.Create(awaiter));
{ }
UniTaskScheduler.PublishUnobservedTaskException(ex);
}
}
}, StateTuple.Create(awaiter));
} }
public static void Forget<T>(this UniTask<T> task, Action<Exception> exceptionHandler, bool handleExceptionOnMainThread = true) public static void Forget<T>(this UniTask<T> task, Action<Exception> exceptionHandler, bool handleExceptionOnMainThread = true)