/// <summary> /// Subscribes the first observer to this subject and /// starts replaying/relaying signals. All future /// observers receive an InvalidOperationException. /// </summary> /// <param name="observer">The observer to subscribe with.</param> public void Subscribe(ISignalObserver <T> observer) { ValidationHelper.RequireNonNullRef(observer, nameof(observer)); if (Interlocked.CompareExchange(ref once, 1, 0) == 0) { var inner = new MonocastDisposable(observer, this); observer.OnSubscribe(inner); if (Interlocked.CompareExchange(ref this.observer, inner, null) == null) { if (inner.IsDisposed()) { this.observer = null; } else { Drain(); } } } else { DisposableHelper.Error(observer, new InvalidOperationException("MonocastSubject allows at most one observer")); } }
public void OnSubscribe(IDisposable d) { this.upstream = d; try { onSubscribe?.Invoke(d); } catch (Exception ex) { try { onDispose?.Invoke(); } catch (Exception exc) { ex = new AggregateException(ex, exc); } upstream.Dispose(); upstream = DisposableHelper.DISPOSED; DisposableHelper.Error(downstream, ex); Finally(); return; } downstream.OnSubscribe(this); }
public void Subscribe(ISignalObserver <T> observer) { ValidationHelper.RequireNonNull(observer, nameof(observer)); var errorSignals = new PublishSubject <Exception>(); var redo = default(IObservableSource <U>); try { redo = ValidationHelper.RequireNonNullRef(handler(errorSignals), "The handler returned a null IObservableSource"); } catch (Exception ex) { DisposableHelper.Error(observer, ex); return; } var parent = new MainObserver(observer, source, new SerializedSignalObserver <Exception>(errorSignals)); observer.OnSubscribe(parent); redo.Subscribe(parent.handlerObserver); parent.HandlerNext(); }
public void Subscribe(ISingleObserver <T> 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; } SingleAmbCoordinator <T> .Run(observer, n, a); }
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 Subscribe(ICompletableObserver observer) { RequireNonNull(observer, nameof(observer)); var completeSignals = new UnicastSubject <object>(); var redo = default(IObservable <U>); try { redo = RequireNonNullRef(handler(completeSignals), "The handler returned a null IObservable"); } catch (Exception ex) { DisposableHelper.Error(observer, ex); return; } var parent = new MainObserver(observer, source, new SerializedObserver <object>(completeSignals)); var d = redo.Subscribe(parent.handlerObserver); parent.handlerObserver.OnSubscribe(d); parent.HandlerNext(); }
public void Subscribe(ICompletableObserver observer) { var srcs = sources; var n = 0; var o = new ICompletableSource[8]; try { foreach (var s in srcs) { if (n == o.Length) { var b = new ICompletableSource[n + (n >> 2)]; Array.Copy(o, 0, b, 0, n); o = b; } o[n++] = s; } } catch (Exception ex) { DisposableHelper.Error(observer, ex); return; } CompletableAmb.Subscribe(observer, o, n); }
public void Subscribe(ICompletableObserver observer) { if (maxConcurrency == int.MaxValue) { var parent = new MergeAllCoordinator(observer, delayErrors); observer.OnSubscribe(parent); parent.SubscribeAll(sources); } else { var en = default(IEnumerator <ICompletableSource>); try { en = sources.GetEnumerator(); } catch (Exception ex) { DisposableHelper.Error(observer, ex); return; } var parent = new MergeLimitedCoordinator(observer, en, delayErrors, maxConcurrency); observer.OnSubscribe(parent); parent.Drain(); } }
public void Subscribe(ISignalObserver <T> observer) { var resource = default(S); try { resource = resourceSupplier(); } catch (Exception ex) { DisposableHelper.Error(observer, ex); return; } var source = default(IObservableSource <T>); try { source = ValidationHelper.RequireNonNullRef(sourceSelector(resource), "The sourceSelector returned a null IObservableSource"); } catch (Exception ex) { if (eager) { try { resourceCleanup?.Invoke(resource); } catch (Exception exc) { ex = new AggregateException(ex, exc); } } DisposableHelper.Error(observer, ex); if (!eager) { try { resourceCleanup?.Invoke(resource); } catch (Exception) { // what to do with these? } } return; } source.Subscribe(new UsingObserver(observer, resource, resourceCleanup, eager)); }
public void Subscribe(IMaybeObserver <T> observer) { var resource = default(S); try { resource = resourceSupplier(); } catch (Exception ex) { DisposableHelper.Error(observer, ex); return; } var c = default(IMaybeSource <T>); try { c = RequireNonNullRef(sourceSelector(resource), "The sourceSelector returned an null IMaybeSource"); } catch (Exception ex) { if (eagerCleanup) { try { resourceCleanup(resource); } catch (Exception exc) { ex = new AggregateException(ex, exc); } DisposableHelper.Error(observer, ex); } else { DisposableHelper.Error(observer, ex); try { resourceCleanup(resource); } catch (Exception) { // TODO where could this go??? } } return; } c.Subscribe(new UsingObserver(observer, resource, resourceCleanup, eagerCleanup)); }
public void Subscribe(ISignalObserver <C> observer) { var coll = default(C); try { coll = initialSupplier(); } catch (Exception ex) { DisposableHelper.Error(observer, ex); return; } source.Subscribe(new ReduceObserver(observer, reducer, coll)); }
public void Subscribe(ISingleObserver <T> observer) { var c = default(ISingleSource <T>); try { c = ValidationHelper.RequireNonNullRef(supplier(), "The supplier returned a null ISingleSource"); } catch (Exception ex) { DisposableHelper.Error(observer, ex); return; } c.Subscribe(observer); }
public void Subscribe(ISignalObserver <T> observer) { var srcs = default(IObservableSource <T>[]); try { srcs = sources.ToArray(); } catch (Exception ex) { DisposableHelper.Error(observer, ex); return; } ObservableSourceAmbCoordinator <T> .Subscribe(observer, srcs); }
public void Subscribe(ISignalObserver <T> observer) { var source = default(IObservableSource <T>); try { source = RequireNonNullRef(supplier(), "The supplier returned a null IObservableSource"); } catch (Exception ex) { DisposableHelper.Error(observer, ex); return; } source.Subscribe(observer); }
public void Subscribe(ICompletableObserver observer) { var en = default(IEnumerator <ICompletableSource>); try { en = RequireNonNullRef(sources.GetEnumerator(), "The sources returned a null IEnumerator"); } catch (Exception ex) { DisposableHelper.Error(observer, ex); return; } var parent = new ConcatDisposable(observer, en, delayErrors); observer.OnSubscribe(parent); parent.Drain(); }
public void Subscribe(ISignalObserver <T> observer) { var en = default(IEnumerator <T>); try { en = ValidationHelper.RequireNonNullRef(source.GetEnumerator(), "The GetEnumerator returned a null IEnumeration"); } catch (Exception ex) { DisposableHelper.Error(observer, ex); return; } var parent = new EnumerableDisposable(observer, en); observer.OnSubscribe(parent); parent.Run(); }
public void Subscribe(ISignalObserver <T> observer) { var en = default(IEnumerator <IObservableSource <T> >); try { en = ValidationHelper.RequireNonNullRef(sources.GetEnumerator(), "The GetEnumerator returned a null IEnumerator"); } catch (Exception ex) { DisposableHelper.Error(observer, ex); return; } var parent = new ConcatObserver(observer, en, delayErrors); observer.OnSubscribe(parent); parent.Next(); }
public void Subscribe(ISignalObserver <R> observer) { var subject = default(IObservableSubject <T>); var observable = default(IObservableSource <R>); try { subject = RequireNonNullRef(subjectFactory(), "The subjectFactory returned a null IObservableSubject"); observable = RequireNonNullRef(handler(subject), "The handler returned a null IObservableSource"); } catch (Exception ex) { DisposableHelper.Error(observer, ex); return; } var parent = new MulticastObserver(observer, subject); observer.OnSubscribe(parent); observable.Subscribe(parent); source.Subscribe(parent.mainObserver); }
public void Subscribe(ISignalObserver <R> observer) { var connectable = default(IConnectableObservableSource <U>); var observable = default(IObservableSource <R>); try { connectable = RequireNonNullRef(connectableSelector(source), "The subjectFactory returned a null IConnectableObservableSource"); observable = RequireNonNullRef(handler(connectable), "The handler returned a null IObservableSource"); } catch (Exception ex) { DisposableHelper.Error(observer, ex); return; } var parent = new MulticastObserver(observer); observer.OnSubscribe(parent); observable.Subscribe(parent); connectable.Connect(d => parent.SetConnection(d)); }
public void Subscribe(ISignalObserver <T> observer) { if (maxConcurrency == int.MaxValue) { var en = default(IEnumerator <IObservableSource <T> >); try { en = RequireNonNullRef(sources.GetEnumerator(), "The GetEnumerator returned a null IEnumerator"); } catch (Exception ex) { DisposableHelper.Error(observer, ex); return; } var parent = new MergeMaxCoordinator(observer, delayErrors); observer.OnSubscribe(parent); for (; ;) { var b = false; var src = default(IObservableSource <T>); try { b = en.MoveNext(); if (b) { src = RequireNonNullRef(en.Current, "The enumerator returned a null IObservableSource"); } } catch (Exception ex) { parent.Error(ex); en.Dispose(); return; } if (b) { if (!parent.SubscribeTo(src)) { en.Dispose(); break; } } else { en.Dispose(); break; } } parent.SetDone(); } else { var en = default(IEnumerator <IObservableSource <T> >); try { en = RequireNonNullRef(sources.GetEnumerator(), "The GetEnumerator returned a null IEnumerator"); } catch (Exception ex) { DisposableHelper.Error(observer, ex); return; } var parent = new MergeLimitedCoordinator(observer, delayErrors, maxConcurrency, en); observer.OnSubscribe(parent); parent.Drain(); } }
public void Subscribe(ISignalObserver <T> observer) { DisposableHelper.Error(observer, error); }