public void OnPull() { if (_stage._maxBuffer == 0) { if (_pendingOffer != null) { Push(_stage.Out, _pendingOffer.Element); _pendingOffer.CompletionSource.SetResult(QueueOfferResult.Enqueued.Instance); _pendingOffer = null; if (_terminating) { _completion.SetResult(new object()); CompleteStage(); } } } else if (_buffer.NonEmpty) { Push(_stage.Out, _buffer.Dequeue()); if (_pendingOffer != null) { EnqueueAndSuccess(_pendingOffer); _pendingOffer = null; } } if (_terminating && _buffer.IsEmpty) { _completion.SetResult(new object()); CompleteStage(); } }
public Logic(QueueSource <TOut> source, TaskCompletionSource <object> completion) : base(source.Shape) { _completion = completion; _source = source; SetHandler(source.Out, onDownstreamFinish: () => { if (_pendingOffer != null) { _pendingOffer.CompletionSource.SetResult(QueueOfferResult.QueueClosed.Instance); _pendingOffer = null; } _completion.SetResult(new object()); CompleteStage(); }, onPull: () => { if (_source._maxBuffer == 0) { if (_pendingOffer != null) { Push(source.Out, _pendingOffer.Element); _pendingOffer.CompletionSource.SetResult(QueueOfferResult.Enqueued.Instance); _pendingOffer = null; if (_terminating) { _completion.SetResult(new object()); CompleteStage(); } } } else if (_buffer.NonEmpty) { Push(source.Out, _buffer.Dequeue()); if (_pendingOffer != null) { EnqueueAndSuccess(_pendingOffer); _pendingOffer = null; } } if (_terminating && _buffer.IsEmpty) { _completion.SetResult(new object()); CompleteStage(); } }); }
public Logic(QueueSource <TOut> source) : base(source.Shape) { _source = source; SetHandler(source.Shape.Outlet, onDownstreamFinish: () => { if (_pendingOffer != null) { var promise = _pendingOffer.Item2; promise.SetResult(QueueOfferResult.QueueClosed.Instance); _pendingOffer = null; } _source._completion.SetResult(new object()); CompleteStage(); }, onPull: () => { if (_source._maxBuffer == 0) { if (_pendingOffer != null) { var element = _pendingOffer.Item1; var promise = _pendingOffer.Item2; Push(source.Shape.Outlet, element); promise.SetResult(QueueOfferResult.Enqueued.Instance); _pendingOffer = null; } else { _pulled = true; } } else if (!_buffer.IsEmpty) { Push(source.Shape.Outlet, _buffer.Dequeue()); if (_pendingOffer != null) { var element = _pendingOffer.Item1; var promise = _pendingOffer.Item2; EnqueueAndSuccess(element, promise); } } else { _pulled = true; } }); }
protected virtual bool RequestElement(object message) { if (message is Request) { // totalDemand is tracked by base if (BufferSize != 0) { while (TotalDemand > 0L && !Buffer.IsEmpty) { OnNext(Buffer.Dequeue()); } } return(true); } return(false); }
private void PushOut() { var src = _q.Dequeue(); Push(_stage._out, src.Grab()); if (!src.IsClosed) { src.Pull(); } else { RemoveSource(src); } }
private void SendDownstream(TaskCompletionSource <Option <T> > promise) { var e = _buffer.Dequeue(); if (e.IsSuccess) { promise.SetResult(e.Value); if (!e.Value.HasValue) { CompleteStage(); } } else { promise.SetException(e.Exception); FailStage(e.Exception); } }
/// <summary> /// TBD /// </summary> /// <returns>TBD</returns> public T Dequeue() => _q.Dequeue();