diff --git a/src/DotNext.IO/IO/PoolingBufferedStream.cs b/src/DotNext.IO/IO/PoolingBufferedStream.cs index a5d32b9dd..52c42cc2d 100644 --- a/src/DotNext.IO/IO/PoolingBufferedStream.cs +++ b/src/DotNext.IO/IO/PoolingBufferedStream.cs @@ -213,27 +213,13 @@ public void Write() /// The task representing asynchronous execution of the operation. /// The operation has been canceled. /// The stream is disposed. - public ValueTask WriteAsync(CancellationToken token = default) + public async ValueTask WriteAsync(CancellationToken token = default) { - ValueTask task; - if (stream is null) - { - task = new(DisposedTask); - } - else if (stream.CanWrite) - { - task = WriteCoreAsync(token); - } - else - { - task = ValueTask.FromException(new NotSupportedException()); - } - - return task; - } + AssertState(); + ThrowIfDisposed(); + if (!stream.CanWrite) + throw new NotSupportedException(); - private async ValueTask WriteCoreAsync(CancellationToken token) - { await WriteCoreAsync(out var isWritten, token).ConfigureAwait(false); if (isWritten) Reset();