Fix IObservable.ToUniTask does not propagate unobserved exception

master
neuecc 2022-03-03 07:40:28 +09:00
parent f63212aa17
commit 62ca0c6e92
1 changed files with 10 additions and 5 deletions

View File

@ -74,16 +74,19 @@ namespace Cysharp.Threading.Tasks
static async UniTaskVoid Fire<T>(AsyncSubject<T> subject, UniTask<T> task) static async UniTaskVoid Fire<T>(AsyncSubject<T> subject, UniTask<T> task)
{ {
T value;
try try
{ {
var value = await task; value = await task;
subject.OnNext(value);
subject.OnCompleted();
} }
catch (Exception ex) catch (Exception ex)
{ {
subject.OnError(ex); subject.OnError(ex);
return;
} }
subject.OnNext(value);
subject.OnCompleted();
} }
static async UniTaskVoid Fire(AsyncSubject<AsyncUnit> subject, UniTask task) static async UniTaskVoid Fire(AsyncSubject<AsyncUnit> subject, UniTask task)
@ -91,13 +94,15 @@ namespace Cysharp.Threading.Tasks
try try
{ {
await task; await task;
subject.OnNext(AsyncUnit.Default);
subject.OnCompleted();
} }
catch (Exception ex) catch (Exception ex)
{ {
subject.OnError(ex); subject.OnError(ex);
return;
} }
subject.OnNext(AsyncUnit.Default);
subject.OnCompleted();
} }
class ToUniTaskObserver<T> : IObserver<T> class ToUniTaskObserver<T> : IObserver<T>