-
-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure lockfree public async methods enforce asynchronous continuations.
- Loading branch information
1 parent
a27d7a7
commit 8f642df
Showing
7 changed files
with
70 additions
and
24 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
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
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
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
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
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,32 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace Nito.AsyncEx.Internals; | ||
|
||
internal static class AsyncUtility | ||
{ | ||
public static Task ForceAsync(Task task) | ||
{ | ||
_ = task ?? throw new ArgumentNullException(nameof(task)); | ||
return task.IsCompleted ? task : ForceAsyncCore(task); | ||
|
||
static async Task ForceAsyncCore(Task task) | ||
{ | ||
await task.ConfigureAwait(false); | ||
await Task.Yield(); | ||
} | ||
} | ||
|
||
public static Task<TResult> ForceAsync<TResult>(Task<TResult> task) | ||
{ | ||
_ = task ?? throw new ArgumentNullException(nameof(task)); | ||
return task.IsCompleted ? task : ForceAsyncCore(task); | ||
|
||
static async Task<TResult> ForceAsyncCore(Task<TResult> task) | ||
{ | ||
var result = await task.ConfigureAwait(false); | ||
await Task.Yield(); | ||
return result; | ||
} | ||
} | ||
} |
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