private async Task WriteAsync()
        {
            using var netStream = new NetworkStream(QuickSocket.Socket);

            while (Write)
            {
                if (await MessageChannelReader.WaitToReadAsync().ConfigureAwait(false))
                {
                    var itemToSend = await MessageChannelReader
                                     .ReadAsync()
                                     .ConfigureAwait(false);

                    var bytes = JsonSerializer.Serialize(itemToSend);

                    try
                    {
                        await FramingStrategy
                        .CreateFrameAndSendAsync(bytes, netStream)
                        .ConfigureAwait(false);
                    }
                    catch
                    {
                        // Stop Writing loop.
                        await StopWriteAsync().ConfigureAwait(false);

                        // Return message to channel.
                        await MessageChannelWriter
                        .WriteAsync(itemToSend)
                        .ConfigureAwait(false);
                    }
                }
            }
        }
 public async Task QueueForWritingAsync(TSend obj)
 {
     if (await MessageChannelWriter.WaitToWriteAsync().ConfigureAwait(false))
     {
         await MessageChannelWriter
         .WriteAsync(obj)
         .ConfigureAwait(false);
     }
 }
Exemple #3
0
 public async Task QueueForWritingAsync(byte[] array)
 {
     if (await MessageChannelWriter.WaitToWriteAsync().ConfigureAwait(false))
     {
         await MessageChannelWriter
         .WriteAsync(array)
         .ConfigureAwait(false);
     }
 }