diff --git a/apiCount.include.md b/apiCount.include.md index f7b72f53..b31438dc 100644 --- a/apiCount.include.md +++ b/apiCount.include.md @@ -1 +1 @@ -**API count: 339** \ No newline at end of file +**API count: 340** \ No newline at end of file diff --git a/api_list.include.md b/api_list.include.md index 148cd529..20c1f6da 100644 --- a/api_list.include.md +++ b/api_list.include.md @@ -280,6 +280,7 @@ #### Stream * `Task CopyToAsync(Stream, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.stream.copytoasync#system-io-stream-copytoasync(system-io-stream-system-threading-cancellationtoken)) + * `ValueTask DisposeAsync()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.stream.disposeasync) * `ValueTask ReadAsync(Memory, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.stream.readasync#system-io-stream-readasync(system-memory((system-byte))-system-threading-cancellationtoken)) * `ValueTask WriteAsync(ReadOnlyMemory, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.stream.writeasync#system-io-stream-writeasync(system-readonlymemory((system-byte))-system-threading-cancellationtoken)) diff --git a/readme.md b/readme.md index 1439c4a4..35812ac1 100644 --- a/readme.md +++ b/readme.md @@ -12,7 +12,7 @@ The package targets `netstandard2.0` and is designed to support the following ru * `net5.0`, `net6.0`, `net7.0`, `net8.0`, `net9.0` -**API count: 339** +**API count: 340** **See [Milestones](../../milestones?state=closed) for release notes.** @@ -737,6 +737,7 @@ The class `Polyfill` includes the following extension methods: #### Stream * `Task CopyToAsync(Stream, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.stream.copytoasync#system-io-stream-copytoasync(system-io-stream-system-threading-cancellationtoken)) + * `ValueTask DisposeAsync()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.stream.disposeasync) * `ValueTask ReadAsync(Memory, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.stream.readasync#system-io-stream-readasync(system-memory((system-byte))-system-threading-cancellationtoken)) * `ValueTask WriteAsync(ReadOnlyMemory, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.io.stream.writeasync#system-io-stream-writeasync(system-readonlymemory((system-byte))-system-threading-cancellationtoken)) diff --git a/src/Consume/Consume.cs b/src/Consume/Consume.cs index e2dfb39a..5f556d13 100644 --- a/src/Consume/Consume.cs +++ b/src/Consume/Consume.cs @@ -421,6 +421,9 @@ async Task Stream_Methods() var read = await stream.ReadAsync(memory); #endif await stream.CopyToAsync(stream); + #if FeatureValueTask + await stream.DisposeAsync(); + #endif } async Task StreamReader_Methods() diff --git a/src/Polyfill/Polyfill_Stream_DisposeAsync.cs b/src/Polyfill/Polyfill_Stream_DisposeAsync.cs new file mode 100644 index 00000000..c67a080e --- /dev/null +++ b/src/Polyfill/Polyfill_Stream_DisposeAsync.cs @@ -0,0 +1,33 @@ +// +#pragma warning disable + +#if (NETFRAMEWORK || NETSTANDARD2_0 || NETCOREAPP2X) && FeatureValueTask + +namespace Polyfills; +using System; +using System.IO; +using System.Threading; +using System.Threading.Tasks; +using Link = System.ComponentModel.DescriptionAttribute; + +static partial class Polyfill +{ + //https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/IO/Stream.cs#L174 + /// + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously. + /// + [Link("https://learn.microsoft.com/en-us/dotnet/api/system.io.stream.disposeasync")] + public static ValueTask DisposeAsync(this Stream target) + { + try + { + target.Dispose(); + return default; + } + catch (Exception exception) + { + return new ValueTask(Task.FromException(exception)); + } + } +} +#endif \ No newline at end of file