public IDisposable Observe(IEventObserver <TEvent, TContext, TModel> observer) { lock (_gate) { _observers.Add(observer); } _observationRegistrar.IncrementRegistration <TEvent>(); return(EspDisposable.Create(() => { lock (_gate) { _observers.Remove(observer); } _observationRegistrar.DecrementRegistration <TEvent>(); })); }
public IDisposable Observe(IModelObserver <T> observer) { lock (_gate) { _observers.Add(observer); } if (_lastValueSet) { observer.OnNext(_lastValue); } return(EspDisposable.Create(() => { lock (_gate) { _observers.Remove(observer); } })); }
public static IEventObservable <TEvent, TContext, TModel> Create <TEvent, TContext, TModel>(Func <IEventObserver <TEvent, TContext, TModel>, Action> subscribe) { Func <IEventObserver <TEvent, TContext, TModel>, IDisposable> subscribe1 = o => EspDisposable.Create(subscribe(o)); return(new EventObservable <TEvent, TContext, TModel>(subscribe1)); }