Skip to content

Instantly share code, notes, and snippets.

@Theby
Created December 21, 2025 20:17
Show Gist options
  • Select an option

  • Save Theby/1fb77671f2e6e6d0d0b586b080404206 to your computer and use it in GitHub Desktop.

Select an option

Save Theby/1fb77671f2e6e6d0d0b586b080404206 to your computer and use it in GitHub Desktop.
Handy extension class to use TaskCompletionSource on demand
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