UniRx 에셋 추가
This commit is contained in:
69
Gameton-06/Assets/Plugins/UniRx/Scripts/Operators/Throw.cs
Normal file
69
Gameton-06/Assets/Plugins/UniRx/Scripts/Operators/Throw.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
|
||||
namespace UniRx.Operators
|
||||
{
|
||||
internal class ThrowObservable<T> : OperatorObservableBase<T>
|
||||
{
|
||||
readonly Exception error;
|
||||
readonly IScheduler scheduler;
|
||||
|
||||
public ThrowObservable(Exception error, IScheduler scheduler)
|
||||
: base(scheduler == Scheduler.CurrentThread)
|
||||
{
|
||||
this.error = error;
|
||||
this.scheduler = scheduler;
|
||||
}
|
||||
|
||||
protected override IDisposable SubscribeCore(IObserver<T> observer, IDisposable cancel)
|
||||
{
|
||||
observer = new Throw(observer, cancel);
|
||||
|
||||
if (scheduler == Scheduler.Immediate)
|
||||
{
|
||||
observer.OnError(error);
|
||||
return Disposable.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
return scheduler.Schedule(() =>
|
||||
{
|
||||
observer.OnError(error);
|
||||
observer.OnCompleted();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class Throw : OperatorObserverBase<T, T>
|
||||
{
|
||||
public Throw(IObserver<T> observer, IDisposable cancel)
|
||||
: base(observer, cancel)
|
||||
{
|
||||
}
|
||||
|
||||
public override void OnNext(T value)
|
||||
{
|
||||
try
|
||||
{
|
||||
base.observer.OnNext(value);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Dispose();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnError(Exception error)
|
||||
{
|
||||
try { observer.OnError(error); }
|
||||
finally { Dispose(); }
|
||||
}
|
||||
|
||||
public override void OnCompleted()
|
||||
{
|
||||
try { observer.OnCompleted(); }
|
||||
finally { Dispose(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user