Created
June 25, 2024 13:54
-
-
Save Cologler/ac92a60b5874195689f5f5f6e47db05d to your computer and use it in GitHub Desktop.
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 PromiseLike | |
{ | |
public static Task Create(Action<TaskCompletionSource> action) | |
{ | |
ThrowIfNull(action); | |
var tcs = new TaskCompletionSource(); | |
action.Invoke(tcs); | |
return tcs.Task; | |
} | |
public static Task<T> Create<T>(Action<TaskCompletionSource<T>> action) | |
{ | |
ThrowIfNull(action); | |
var tcs = new TaskCompletionSource<T>(); | |
action.Invoke(tcs); | |
return tcs.Task; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment