Skip to content

Commit

Permalink
[Storage] Implement IAsyncDisposable in StorageWriteStream (Azure#48628)
Browse files Browse the repository at this point in the history
* Implemented DisposeAsync in StorageWriteStream

* feedback
  • Loading branch information
nickliu-msft authored Mar 7, 2025
1 parent 10ad7e3 commit 1a90ea9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions sdk/storage/Azure.Storage.Common/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Fixed bug where LazyLoadingReadOnlyStream overprovisions the default buffer memory for OpenRead

### Other Changes
- Implemented IAsyncDisposable in StorageWriteStream

## 12.23.0-beta.1 (2025-02-11)

Expand Down
24 changes: 24 additions & 0 deletions sdk/storage/Azure.Storage.Common/src/Shared/StorageWriteStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,30 @@ protected override void Dispose(bool disposing)
base.Dispose(disposing);
}

#if NETCOREAPP3_0_OR_GREATER || NETCORESTANDARD2_1_OR_GREATER
public override async ValueTask DisposeAsync()
{
if (_disposed)
{
return;
}

try
{
await FlushAsync(cancellationToken: default).ConfigureAwait(false);
ValidateCallerCrcIfAny();
}
finally
{
_accumulatedDisposables.Dispose();
}

_disposed = true;

await base.DisposeAsync().ConfigureAwait(false);
}
#endif

private void ValidateCallerCrcIfAny()
{
if (UseMasterCrc && !_userProvidedChecksum.IsEmpty)
Expand Down

0 comments on commit 1a90ea9

Please sign in to comment.