Пример #1
0
        public IObservable <Change <TObject, TKey> > Watch(TKey key)
        {
            return(Observable.Create <Change <TObject, TKey> >
                   (
                       observer =>
            {
                lock (_locker)
                {
                    var initial = _readerWriter.Lookup(key);
                    if (initial.HasValue)
                    {
                        observer.OnNext(new Change <TObject, TKey>(ChangeReason.Add, key, initial.Value));
                    }

                    return _changes.FinallySafe(observer.OnCompleted).Subscribe(changes =>
                    {
                        var matches = changes.Where(update => update.Key.Equals(key));
                        foreach (var match in matches)
                        {
                            observer.OnNext(match);
                        }
                    });
                }
            }));
        }
 public Optional <TObject> Lookup(TKey key)
 {
     return(_readerWriter.Lookup(key));
 }