public void Error() { IMaybeSource <int> src = SingleSource.Error <int>(new InvalidOperationException()) .ToMaybe(); src.Test().AssertFailure(typeof(InvalidOperationException)); }
public void Subscribe(IMaybeObserver <R> observer) { var n = 0; var srcs = sources; var a = new IMaybeSource <T> [8]; try { foreach (var m in srcs) { if (n == a.Length) { var b = new IMaybeSource <T> [n + (n >> 2)]; Array.Copy(a, 0, b, 0, n); a = b; } a[n++] = m; } } catch (Exception ex) { DisposableHelper.Error(observer, ex); return; } MaybeZipCoordinator <T, R> .Run(a, n, observer, mapper, delayErrors); }
public void Array_Limit_Null() { for (int i = 1; i < 10; i++) { var to = new IMaybeSource <int>[] { MaybeSource.Just(1), MaybeSource.Empty <int>(), null } .ConcatEagerAll(maxConcurrency: i) .Test() .WithTag($"maxConcurrency={i}"); if (i >= 3) { // error cuts ahead to.AssertFailure(typeof(NullReferenceException)); } else { to.AssertFailure(typeof(NullReferenceException), 1); } } }
public MaybeTimeout(IMaybeSource <T> source, TimeSpan timeout, IScheduler scheduler, IMaybeSource <T> fallback) { this.source = source; this.timeout = timeout; this.scheduler = scheduler; this.fallback = fallback; }
public void Success() { IMaybeSource <int> src = SingleSource.Just(1) .ToMaybe(); src.Test().AssertResult(1); }
internal void Run() { var o = other; other = null; o.Subscribe(this); }
internal bool SubscribeTo(IMaybeSource <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 MaybeInnerObserver <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 MaybeInnerObserver <T>(downstream); if (DisposableHelper.Replace(ref upstream, inner)) { o.Subscribe(inner); } }
internal void Drain(IMaybeSource <T> source) { if (Interlocked.Increment(ref wip) == 1) { for (; ;) { if (!DisposableHelper.IsDisposed(ref upstream)) { if (source != null) { source.Subscribe(this); source = null; } else { var idx = index; if (idx == fallbacks.Length) { DisposableHelper.WeakDispose(ref upstream); downstream.OnCompleted(); } else { var src = fallbacks[idx]; if (src == null) { DisposableHelper.WeakDispose(ref upstream); downstream.OnError(new NullReferenceException("The fallback IMaybeSource at index " + idx + " is null")); } else { index = idx + 1; src.Subscribe(this); } } } } if (Interlocked.Decrement(ref wip) == 0) { break; } } } }
public void Array_Success_Many() { for (int i = 1; i < 32; i++) { var o = new IMaybeSource <int> [i]; var src = MaybeSource.Just(1); for (int j = 0; j < o.Length; j++) { o[j] = src; } o.Zip(Sum) .Test() .AssertResult(i); } }
public void OnCompleted() { if (next == null) { downstream.OnCompleted(); Dispose(); } else { if (DisposableHelper.Replace(ref upstream, null)) { var src = next; next = null; src.Subscribe(this); } } }
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; } } }
internal void Subscribe(IMaybeSource <T>[] sources, int n) { for (int i = 0; i < n; i++) { IMaybeSource <T> src = sources[i]; if (src == null) { var ex = new NullReferenceException("The IMaybeSource at index " + i + " is null"); InnerError(ex); Interlocked.Add(ref active, -(n - i)); Drain(); break; } if (!SubscribeTo(src)) { break; } } }
public bool SubscribeTo(IMaybeSource <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 IMaybeSource is null")); return(true); } source.Subscribe(inner); return(true); }
internal static IMaybeSource <T> Create(IMaybeSource <T> source, Action <T> onSuccess = null, Action <T> onAfterSuccess = null, Action <Exception> onError = null, Action onCompleted = null, Action <IDisposable> onSubscribe = null, Action onTerminate = null, Action onAfterTerminate = null, Action onDispose = null, Action doFinally = null ) { if (source is MaybePeek <T> p) { return(new MaybePeek <T>(p.source, Combine(p.onSuccess, onSuccess), Combine(p.onAfterSuccess, onAfterSuccess), Combine(p.onError, onError), Combine(p.onCompleted, onCompleted), Combine(p.onSubscribe, onSubscribe), Combine(p.onTerminate, onTerminate), Combine(p.onAfterTerminate, onAfterTerminate), Combine(p.onDispose, onDispose), Combine(p.doFinally, doFinally) )); } return(new MaybePeek <T>(source, onSuccess, onAfterSuccess, onError, onCompleted, onSubscribe, onTerminate, onAfterTerminate, onDispose, doFinally )); }
public MaybePeek( IMaybeSource <T> source, Action <T> onSuccess, Action <T> onAfterSuccess, Action <Exception> onError, Action onCompleted, Action <IDisposable> onSubscribe, Action onTerminate, Action onAfterTerminate, Action onDispose, Action doFinally) { this.source = source; this.onSuccess = onSuccess; this.onAfterSuccess = onAfterSuccess; this.onError = onError; this.onCompleted = onCompleted; 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 MaybeInnerObserver <T>(downstream); if (Interlocked.CompareExchange(ref fallbackObserver, inner, null) == null) { c.Subscribe(inner); } } } }
public MaybeHide(IMaybeSource <T> source) { this.source = source; }
public MaybeObserveOn(IMaybeSource <T> source, IScheduler scheduler) { this.source = source; this.scheduler = scheduler; }
public MaybeOnErrorComplete(IMaybeSource <T> source) { this.source = source; }
public MaybeSwitchIfEmptyMany(IMaybeSource <T> source, IMaybeSource <T>[] fallback) { this.source = source; this.fallback = fallback; }
public MaybeSwitchIfEmpty(IMaybeSource <T> source, ISingleSource <T> fallback) { this.source = source; this.fallback = fallback; }
public MaybeTakeUntil(IMaybeSource <T> source, IMaybeSource <U> other) { this.source = source; this.other = other; }
public MaybeTakeUntilObservable(IMaybeSource <T> source, IObservable <U> other) { this.source = source; this.other = other; }
public MaybeRedoWhenObserver(IMaybeSource <T> source, IObserver <X> terminalSignal) { this.source = source; this.terminalSignal = terminalSignal; this.redoObserver = new RedoObserver(this); }
public MaybeToSingle(IMaybeSource <T> source) { this.source = source; }
public MaybeFlatMapEnumerable(IMaybeSource <T> source, Func <T, IEnumerable <R> > mapper) { this.source = source; this.mapper = mapper; }
public MaybeMap(IMaybeSource <T> source, Func <T, R> mapper) { this.source = source; this.mapper = mapper; }
public MaybeFlatMapSingle(IMaybeSource <T> source, Func <T, ISingleSource <R> > mapper) { this.source = source; this.mapper = mapper; }