123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- using System;
- namespace UniRx.Operators
- {
- internal class AsUnitObservableObservable<T> : OperatorObservableBase<Unit>
- {
- readonly IObservable<T> source;
- public AsUnitObservableObservable(IObservable<T> source)
- : base(source.IsRequiredSubscribeOnCurrentThread())
- {
- this.source = source;
- }
- protected override IDisposable SubscribeCore(IObserver<Unit> observer, IDisposable cancel)
- {
- return source.Subscribe(new AsUnitObservable(observer, cancel));
- }
- class AsUnitObservable : OperatorObserverBase<T, Unit>
- {
- public AsUnitObservable(IObserver<Unit> observer, IDisposable cancel)
- : base(observer, cancel)
- {
- }
- public override void OnNext(T value)
- {
- base.observer.OnNext(Unit.Default);
- }
- public override void OnError(Exception error)
- {
- try { observer.OnError(error); }
- finally { Dispose(); }
- }
- public override void OnCompleted()
- {
- try { observer.OnCompleted(); }
- finally { Dispose(); }
- }
- }
- }
- }
|