Created
December 21, 2025 20:17
-
-
Save Theby/1fb77671f2e6e6d0d0b586b080404206 to your computer and use it in GitHub Desktop.
Handy extension class to use TaskCompletionSource on demand
This file contains hidden or 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
| public static class TaskAsyncExtensions | |
| { | |
| public static Task<T> MakeAsync<T>(Action<Action<T>> syncAction) | |
| { | |
| var taskCompletion = new TaskCompletionSource<T>(TaskCreationOptions.RunContinuationsAsynchronously); | |
| syncAction.Invoke(taskCompletion.SetResult); | |
| return taskCompletion.Task; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment