Example #1
0
        public static async Task TextMessageUsingPipeline()
        {
            var      pipe    = new Pipe();
            IMessage message = new TextMessage("Hello, world!", "msg");

            ThreadPool.QueueUserWorkItem(async state =>
            {
                await message.WriteToAsync(pipe.Writer).ConfigureAwait(false);
                pipe.Writer.Complete();
            });
            using var content = new MemoryStream();
            await pipe.Reader.CopyToAsync(content);

            content.Seek(0, SeekOrigin.Begin);
            using (var reader = new StreamReader(content, Encoding.UTF8, false, 1024, true))
            {
                Equal("Hello, world!", reader.ReadToEnd());
            }
        }