internal SpscLinkedArrayQueue <T> CreateQueue(int capacityHint) { var q = new SpscLinkedArrayQueue <T>(capacityHint); Interlocked.Exchange(ref queue, q); return(q); }
internal ConcatMapEagerObserver(ISignalObserver <R> downstream, Func <T, IObservableSource <R> > mapper, int capacityHint) : base(downstream) { this.mapper = mapper; this.capacityHint = capacityHint; this.observers = new SpscLinkedArrayQueue <InnerSignalObserver <R> >(capacityHint); }
void TryEmitScalar(IDynamicValue <R> d) { var v = default(R); var success = false; try { v = d.GetValue(out success); } catch (Exception ex) { if (delayErrors) { ExceptionHelper.AddException(ref errors, ex); } else { Interlocked.CompareExchange(ref errors, ex, null); } Drain(); return; } if (success) { if (Interlocked.CompareExchange(ref wip, 1, 0) == 0) { downstream.OnNext(v); if (Interlocked.Decrement(ref wip) == 0) { return; } } else { var q = scalarQueue; if (q == null) { q = new SpscLinkedArrayQueue <R>(capacityHint); Volatile.Write(ref scalarQueue, q); } q.TryOffer(v); if (Interlocked.Increment(ref wip) != 1) { return; } } DrainLoop(); } }
public FlatMapMainObserver(ISignalObserver <R> downstream, Func <T, IObservableSource <R> > mapper, bool delayErrors, int maxConcurrency, int capacityHint) { this.downstream = downstream; this.mapper = mapper; this.delayErrors = delayErrors; this.maxConcurrency = maxConcurrency; this.capacityHint = capacityHint; if (maxConcurrency == int.MaxValue) { this.sourceQueue = null; } else { this.sourceQueue = new SpscLinkedArrayQueue <T>(capacityHint); } Volatile.Write(ref observers, Empty); }
internal ConcatMapEagerLimitedObserver(ISignalObserver <R> downstream, Func <T, IObservableSource <R> > mapper, int capacityHint, int maxConcurrency) : base(downstream, mapper, capacityHint) { Volatile.Write(ref requested, maxConcurrency); this.queue = new SpscLinkedArrayQueue <T>(capacityHint); }
public ObserveOnObserver(IObserver <T> downstream, IScheduler scheduler, bool delayError) : base(downstream) { this.scheduler = scheduler; this.delayError = delayError; this.queue = new SpscLinkedArrayQueue <T>(128); }
/// <summary> /// Constructs a new UnicastSubject with the given capacity hint (expected /// number of items to be buffered until consumed) and an action to /// call when the UnicastSubject terminates or the observer disposes. /// </summary> /// <param name="capacityHint">The expected number of items to be buffered until consumed.</param> /// <param name="onTerminate">The action to call when the UnicastSubject terminates or the observer disposes.</param> public UnicastSubject(int capacityHint = 128, Action onTerminate = null) { this.queue = new SpscLinkedArrayQueue <T>(capacityHint); Volatile.Write(ref this.onTerminate, onTerminate); }
/// <summary> /// Constructs a MonocastSubject with the default /// or specified capacity hint for the internal queue. /// </summary> /// <param name="capacityHint">The expected number of items to be /// cached.</param> /// <param name="onTerminate">Called when the upstream terminates /// or the single observer disposes, at most once.</param> public MonocastSubject(int capacityHint = 32, Action onTerminate = null) { this.onTerminate = onTerminate; queue = new SpscLinkedArrayQueue <T>(capacityHint); }