Created
December 8, 2021 23:30
-
-
Save madmonkey/afaaed528e63fae6edccfe779f275eab to your computer and use it in GitHub Desktop.
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
static class TaskExtensions | |
{ | |
public static Task AsTask(this CancellationToken cancellationToken, bool useContext = false) | |
{ | |
var tcs = new TaskCompletionSource<object>(); | |
cancellationToken.Register(() => tcs.TrySetCanceled(), useSynchronizationContext: useContext); | |
return tcs.Task; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment