This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement IAsyncDisposable.ConfigureAwait (dotnet/coreclr#22160)
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
- Loading branch information
1 parent
d40bfe3
commit 351ca39
Showing
3 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/Common/src/CoreLib/System/Runtime/CompilerServices/ConfiguredAsyncDisposable.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Runtime.InteropServices; | ||
|
||
namespace System.Runtime.CompilerServices | ||
{ | ||
/// <summary>Provides a type that can be used to configure how awaits on an <see cref="IAsyncDisposable"/> are performed.</summary> | ||
[StructLayout(LayoutKind.Auto)] | ||
public readonly struct ConfiguredAsyncDisposable | ||
{ | ||
private readonly IAsyncDisposable _source; | ||
private readonly bool _continueOnCapturedContext; | ||
|
||
internal ConfiguredAsyncDisposable(IAsyncDisposable source, bool continueOnCapturedContext) | ||
{ | ||
_source = source; | ||
_continueOnCapturedContext = continueOnCapturedContext; | ||
} | ||
|
||
public ConfiguredValueTaskAwaitable DisposeAsync() => | ||
// as with other "configured" awaitable-related type in CompilerServices, we don't null check to defend against | ||
// misuse like `default(ConfiguredAsyncDisposable).DisposeAsync()`, which will null ref by design. | ||
_source.DisposeAsync().ConfigureAwait(_continueOnCapturedContext); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters