Skip to content

Instantly share code, notes, and snippets.

@Cologler
Created June 25, 2024 13:54
Show Gist options
  • Save Cologler/ac92a60b5874195689f5f5f6e47db05d to your computer and use it in GitHub Desktop.
Save Cologler/ac92a60b5874195689f5f5f6e47db05d to your computer and use it in GitHub Desktop.
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