public Watcher(IObservable <IChangeSet <TObject, TKey> > source, IScheduler scheduler) { _source = source.AsObservableCache(); var onCompletePublisher = _subscribers.Connect() .Synchronize(_locker) .ObserveOn(scheduler) .SubscribeMany((t, k) => Disposable.Create(t.OnCompleted)) .Subscribe(); var sourceSubscriber = source.Synchronize(_locker).Subscribe(updates => updates.ForEach(update => { var subscriber = _subscribers.Lookup(update.Key); if (subscriber.HasValue) { scheduler.Schedule(() => subscriber.Value.OnNext(update)); } })); _disposer = Disposable.Create(() => { onCompletePublisher.Dispose(); sourceSubscriber.Dispose(); _source.Dispose(); _subscribers.Dispose(); }); }
public IObservable <IChangeSet <TObject, TKey> > Run() { return(Observable.Create <IChangeSet <TObject, TKey> >(observer => { Interlocked.Increment(ref _refCount); if (Volatile.Read(ref _refCount) == 1) { Interlocked.Exchange(ref _cache, _source.AsObservableCache()); } // ReSharper disable once PossibleNullReferenceException (never the case!) var subscriber = _cache.Connect().SubscribeSafe(observer); return Disposable.Create(() => { Interlocked.Decrement(ref _refCount); subscriber.Dispose(); if (Volatile.Read(ref _refCount) != 0) { return; } _cache.Dispose(); Interlocked.Exchange(ref _cache, null); }); })); }
/// <summary> /// Initializes a new instance of the <see cref="ChangeSetAggregator{TObject, TKey}"/> class. /// </summary> /// <param name="source">The source.</param> public ChangeSetAggregator(IObservable <IChangeSet <TObject, TKey> > source) { var published = source.Publish(); _data = published.AsObservableCache(); var results = published.Subscribe(updates => _messages.Add(updates), ex => _error = ex); var summariser = published.CollectUpdateStats().Subscribe(summary => _summary = summary); var connected = published.Connect(); _disposer = Disposable.Create(() => { _data.Dispose(); connected.Dispose(); summariser.Dispose(); results.Dispose(); }); }
public void Dispose() { _source?.Dispose(); _grouped?.Dispose(); }
public void Dispose() { _sourceCache.Dispose(); _result.Dispose(); }
public void Dispose() { _source?.Dispose(); _controller?.Dispose(); _grouped?.Dispose(); }
public void Dispose() { _cache.Dispose(); }
public void Dispose() { _empData.Dispose(); }
public void Dispose() { _itemCache.Dispose(); }