public void Subscribe(ISingleSubscriber <T> s) { SingleDisposable sd = new SingleDisposable(this, s); s.OnSubscribe(sd); if (Add(sd)) { if (sd.IsDisposed()) { Remove(sd); } if (Volatile.Read(ref once) == 0) { if (Interlocked.CompareExchange(ref once, 1, 0) == 0) { source.Subscribe(this); } } } else { ValueOrError r = Volatile.Read(ref result); if (r.IsError()) { s.OnError(r.error); } else { s.OnSuccess(r.value); } } }
public static IEventReader Once(this IEventReader reader) { return(new AnonymousEventReader((Action reaction) => { var disp = new SingleDisposable(); disp.Disposable = reader.Subscribe(() => { reaction(); disp.Dispose(); }); return disp; })); }
// Result stream is called only once, then the connection is disposed. public static IEventReader <T> Once <T>(this IEventReader <T> eventReader) { return(new AnonymousEventReader <T>((Action <T> reaction) => { var disp = new SingleDisposable(); disp.Disposable = eventReader.Subscribe(val => { reaction(val); disp.Dispose(); }); return disp; })); }
public static IEventStream Once(this IEventStream stream) { return(new AnonymousEventStream((Action reaction) => { var disp = new SingleDisposable(); disp.Disposable = stream.Subscribe(() => { reaction(); disp.Dispose(); }); return disp; })); }
internal bool Remove(SingleDisposable sd) { return(ProcessorHelper.Remove(ref subscribers, sd, Terminated, Empty)); }
internal bool Add(SingleDisposable sd) { return(ProcessorHelper.Add(ref subscribers, sd, Terminated)); }