public Action OnCompleted(Action continuation, ref PipeCompletion completion) { var awaitableState = _state; if (ReferenceEquals(awaitableState, _awaitableIsNotCompleted)) { _state = continuation; } if (ReferenceEquals(awaitableState, _awaitableIsCompleted)) { return(continuation); } if (!ReferenceEquals(awaitableState, _awaitableIsNotCompleted)) { completion.TryComplete(PipelinesThrowHelper.GetInvalidOperationException(ExceptionResource.NoConcurrentOperation)); _state = _awaitableIsCompleted; Task.Run(continuation); Task.Run(awaitableState); } return(null); }
void IAwaiter <FlushResult> .OnCompleted(Action continuation) { Action awaitable; bool doubleCompletion; lock (_sync) { awaitable = _writerAwaitable.OnCompleted(continuation, out doubleCompletion); } if (doubleCompletion) { Reader.Complete(PipelinesThrowHelper.GetInvalidOperationException(ExceptionResource.NoConcurrentOperation)); } TrySchedule(_writerScheduler, awaitable); }