DotNext by .NET Foundation and Contributors

<PackageReference Include="DotNext" Version="4.7.3" />

 SyncWriterStream<TOutput>

sealed class SyncWriterStream<TOutput> : WriterStream<TOutput> where TOutput : IReadOnlySpanConsumer<byte>, IFlushable
using DotNext.Buffers; using System; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; namespace DotNext.IO { internal sealed class SyncWriterStream<TOutput> : WriterStream<TOutput> where TOutput : IReadOnlySpanConsumer<byte>, IFlushable { public override bool CanTimeout => false; internal SyncWriterStream(TOutput output) : base(output) { } public override void Write(ReadOnlySpan<byte> buffer) { output.Invoke(buffer); writtenBytes += buffer.Length; } [AsyncStateMachine(typeof(SyncWriterStream<>.<WriteAsync>d__4))] public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken token) { <WriteAsync>d__4 stateMachine = default(<WriteAsync>d__4); stateMachine.<>t__builder = AsyncValueTaskMethodBuilder.Create(); stateMachine.<>4__this = this; stateMachine.buffer = buffer; stateMachine.token = token; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start<<WriteAsync>d__4>(ref stateMachine); return stateMachine.<>t__builder.Task; } } }