Exemplo n.º 1
0
 private void StartExecution()
 {
     while (!_cancellationToken.IsCancellationRequested)
     {
         _manualResetEvent.WaitOne();
         while (_executionQueue.Count > 0)
         {
             ObserverItem item = default;
             lock (_lock)
             {
                 item = _executionQueue.Dequeue();
             }
             //we can get an exception here if item in queue is bad
             //NRE for example
             if (item.HasException)
             {
                 _observer.OnError(item.Exception);
             }
             else if (!item.IsLastElement)
             {
                 _observer.OnNext(item.Value);
             }
             else
             {
                 _observer.OnCompleted();
                 //we do nothing, when execution was completed
                 //in theory we can still receive items, but I'm not process it, because this class just a wrapper for background consuming
             }
         }
         _manualResetEvent.Reset();
     }
 }
    public IDisposable Subscribe(IObserver <T> observer)
    {
        ObserverItem item = new ObserverItem(observer, this);

        _observerItems.Add(item);
        return(item);
    }
Exemplo n.º 3
0
 private void Enqueue(ObserverItem item)
 {
     lock (_lock)
     {
         _executionQueue.Enqueue(item);
     }
     _manualResetEvent.Set();
 }
Exemplo n.º 4
0
 public void EnqueueLast() => Enqueue(ObserverItem.FromLast());
Exemplo n.º 5
0
 public void EnqueueError(Exception exception) => Enqueue(ObserverItem.FromException(exception));
Exemplo n.º 6
0
 public void EnqueueNext(T value) => Enqueue(ObserverItem.FromValue(value));