public void Error() { ISingleSource <int> src = MaybeSource.Error <int>(new InvalidOperationException()) .ToSingle(); src.Test().AssertFailure(typeof(InvalidOperationException)); }
public void Empty() { ISingleSource <int> src = MaybeSource.Empty <int>() .ToSingle(); src.Test().AssertFailure(typeof(IndexOutOfRangeException)); }
public SingleTimeout(ISingleSource <T> source, TimeSpan timeout, IScheduler scheduler, ISingleSource <T> fallback) { this.source = source; this.timeout = timeout; this.scheduler = scheduler; this.fallback = fallback; }
public void Success() { ISingleSource <int> src = MaybeSource.Just(1) .ToSingle(); src.Test().AssertResult(1); }
public void Subscribe(ISingleObserver <R> observer) { var n = 0; var srcs = sources; var a = new ISingleSource <T> [8]; try { foreach (var m in srcs) { if (n == a.Length) { var b = new ISingleSource <T> [n + (n >> 2)]; Array.Copy(a, 0, b, 0, n); a = b; } a[n++] = m; } } catch (Exception ex) { DisposableHelper.Error(observer, ex); return; } SingleZipCoordinator <T, R> .Run(a, n, observer, mapper, delayErrors); }
internal static ISingleSource <T> Create(ISingleSource <T> source, Action <T> onSuccess = null, Action <T> onAfterSuccess = null, Action <Exception> onError = null, Action <IDisposable> onSubscribe = null, Action onTerminate = null, Action onAfterTerminate = null, Action onDispose = null, Action doFinally = null ) { if (source is SinglePeek <T> p) { return(new SinglePeek <T>(p.source, Combine(p.onSuccess, onSuccess), Combine(p.onAfterSuccess, onAfterSuccess), Combine(p.onError, onError), Combine(p.onSubscribe, onSubscribe), Combine(p.onTerminate, onTerminate), Combine(p.onAfterTerminate, onAfterTerminate), Combine(p.onDispose, onDispose), Combine(p.doFinally, doFinally) )); } return(new SinglePeek <T>(source, onSuccess, onAfterSuccess, onError, onSubscribe, onTerminate, onAfterTerminate, onDispose, doFinally )); }
public void OnCompleted() { var src = fallback; fallback = null; src.Subscribe(this); }
internal void Run() { var o = other; other = null; o.Subscribe(this); }
public void OnCompleted() { if (DisposableHelper.Replace(ref upstream, null)) { var src = next; next = null; src.Subscribe(this); } }
internal bool SubscribeTo(ISingleSource <T> source) { var inner = new InnerObserver(this); if (Add(inner)) { source.Subscribe(inner); return(true); } return(false); }
public void OnError(Exception error) { var inner = new SingleInnerObserver <T>(downstream); if (Interlocked.CompareExchange(ref fallbackObserver, inner, null) == null) { var fb = fallback; fallback = null; fb.Subscribe(inner); } }
void Next() { var o = main; main = null; var inner = new SingleInnerObserver <T>(downstream); if (DisposableHelper.Replace(ref upstream, inner)) { o.Subscribe(inner); } }
public void Array_Limit_Null() { for (int i = 1; i < 10; i++) { var to = new ISingleSource <int>[] { SingleSource.Just(1), null } .ConcatEagerAll(maxConcurrency: i) .Test() .WithTag($"maxConcurrency={i}"); to .AssertNotCompleted() .AssertError(typeof(NullReferenceException)); } }
public void Array_Success_Many() { for (int i = 1; i < 32; i++) { var o = new ISingleSource <int> [i]; var src = SingleSource.Just(1); for (int j = 0; j < o.Length; j++) { o[j] = src; } o.Zip(Sum) .Test() .AssertResult(i); } }
internal void Subscribe(ISingleSource <T>[] sources, int n) { for (int i = 0; i < n; i++) { ISingleSource <T> src = sources[i]; if (src == null) { var ex = new NullReferenceException("The ISingleSource at index " + i + " is null"); InnerError(ex); Interlocked.Add(ref active, -(n - i)); Drain(); break; } if (!SubscribeTo(src)) { break; } } }
public bool SubscribeTo(ISingleSource <T> source) { var inner = new InnerObserver(this); observers.Enqueue(inner); if (Volatile.Read(ref disposed)) { DisposableHelper.WeakDispose(ref inner.upstream); Cleanup(); return(false); } if (source == null) { InnerError(inner, new NullReferenceException("The ISingleSource is null")); return(true); } source.Subscribe(inner); return(true); }
internal void Run() { for (; ;) { var d = Volatile.Read(ref task); if (d == DisposableHelper.DISPOSED) { break; } if (Interlocked.CompareExchange(ref task, DisposableHelper.EMPTY, d) == d) { var s = source; source = null; s.Subscribe(this); break; } } }
public SinglePeek( ISingleSource <T> source, Action <T> onSuccess, Action <T> onAfterSuccess, Action <Exception> onError, Action <IDisposable> onSubscribe, Action onTerminate, Action onAfterTerminate, Action onDispose, Action doFinally) { this.source = source; this.onSuccess = onSuccess; this.onAfterSuccess = onAfterSuccess; this.onError = onError; this.onSubscribe = onSubscribe; this.onTerminate = onTerminate; this.onAfterTerminate = onAfterTerminate; this.onDispose = onDispose; this.doFinally = doFinally; }
internal void Run() { if (Interlocked.CompareExchange(ref exclude, 1, 0) == 0) { DisposableHelper.Dispose(ref upstream); var c = fallback; if (c == null) { downstream.OnError(new TimeoutException()); } else { fallback = null; var inner = new SingleInnerObserver <T>(downstream); if (Interlocked.CompareExchange(ref fallbackObserver, inner, null) == null) { c.Subscribe(inner); } } } }
public TimeoutObserver(ISingleObserver <T> downstream, ISingleSource <T> fallback) { this.downstream = downstream; this.fallback = fallback; }
public CompletableAndThenSingle(ICompletableSource source, ISingleSource <T> next) { this.source = source; this.next = next; }
public MaybeSwitchIfEmpty(IMaybeSource <T> source, ISingleSource <T> fallback) { this.source = source; this.fallback = fallback; }
public SwitchIfEmptyObserver(ISingleObserver <T> downstream, ISingleSource <T> fallback) { this.downstream = downstream; this.fallback = fallback; }
public SingleToObservable(ISingleSource <T> source) { this.source = source; }
public AndThenObserver(ISingleObserver <T> downstream, ISingleSource <T> next) { this.downstream = downstream; Volatile.Write(ref this.next, next); }
public SingleFilter(ISingleSource <T> source, Func <T, bool> predicate) { this.source = source; this.predicate = predicate; }
public SingleOnTerminateDetach(ISingleSource <T> source) { this.source = source; }
public SingleDelay(ISingleSource <T> source, TimeSpan delay, IScheduler scheduler) { this.source = source; this.delay = delay; this.scheduler = scheduler; }
public void OnError(Exception error) { next = null; downstream.OnError(error); }
public SingleFlatMapSingle(ISingleSource <T> source, Func <T, ISingleSource <R> > mapper) { this.source = source; this.mapper = mapper; }