예제 #1
0
        private async Task ApplyBackpressureAsync(WritableBufferAwaitable flushTask)
        {
            Log.ConnectionPause(ConnectionId);
            _socket.ReadStop();

            var result = await flushTask;

            // If the reader isn't complete or cancelled then resume reading
            if (!result.IsCompleted && !result.IsCancelled)
            {
                Log.ConnectionResume(ConnectionId);
                StartReading();
            }
        }
예제 #2
0
        private static async Task Continue(WritableBufferAwaitable awaitable, ReadOperation operation)
        {
            // Keep reading once we get the completion
            if (await awaitable)
            {
                operation.Read();
            }
            else
            {
                operation.Writer.Complete();

                operation.Dispose();
            }
        }
예제 #3
0
        private static async Task Continue(WritableBufferAwaitable awaitable, ReadOperation operation)
        {
            // Keep reading once we get the completion
            var flushResult = await awaitable;

            if (!flushResult.IsCompleted)
            {
                operation.Read();
            }
            else
            {
                operation.Writer.Complete();

                operation.Dispose();
            }
        }
예제 #4
0
        private async Task FlushAsyncAwaited(WritableBufferAwaitable awaitable, long count, CancellationToken cancellationToken)
        {
            // https://github.com/dotnet/corefxlab/issues/1334
            // Since the flush awaitable doesn't currently support multiple awaiters
            // we need to use a task to track the callbacks.
            // All awaiters get the same task
            lock (_flushLock)
            {
                if (_flushTcs == null || _flushTcs.Task.IsCompleted)
                {
                    _flushTcs = new TaskCompletionSource <object>();

                    awaitable.OnCompleted(_flushCompleted);
                }
            }

            await _flushTcs.Task;

            cancellationToken.ThrowIfCancellationRequested();
        }
예제 #5
0
        public static Task AsTask(this WritableBufferAwaitable flush)
        {
            async Task Awaited(WritableBufferAwaitable result)
            {
                if ((await result).IsCancelled)
                {
                    throw new ObjectDisposedException("Flush cancelled");
                }
            }

            if (!flush.IsCompleted)
            {
                return(Awaited(flush));
            }
            if (flush.GetResult().IsCancelled)
            {
                throw new ObjectDisposedException("Flush cancelled");
            }
            return(Task.CompletedTask); // all sync? who knew!
        }