KafkaNet.KafkaTcpSocket.ProcessNetworkstreamTasks C# (CSharp) Method

ProcessNetworkstreamTasks() private method

private ProcessNetworkstreamTasks ( NetworkStream netStream ) : Task
netStream System.Net.Sockets.NetworkStream
return Task
        private async Task ProcessNetworkstreamTasks(NetworkStream netStream)
        {
            //reading/writing from network steam is not thread safe
            //Read and write operations can be performed simultaneously on an instance of the NetworkStream class without the need for synchronization.
            //As long as there is one unique thread for the write operations and one unique thread for the read operations, there will be no cross-interference
            //between read and write threads and no synchronization is required.
            //https://msdn.microsoft.com/en-us/library/z2xae4f4.aspx

            //Exception need to thrown immediately and not depend on the next task
            var readTask = ProcessNetworkstreamsSendTask(netStream);
            var sendTask = ProcessNetworkstreamTasksReadTask(netStream);
            await Task.WhenAny(readTask, sendTask).ConfigureAwait(false);
            if (_disposeToken.IsCancellationRequested) return;
            await ThrowTaskExceptionIfFaulted(readTask);
            await ThrowTaskExceptionIfFaulted(sendTask);
        }