-
-
Save jbogard/889ea1bdd30e0bf7a18f 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
internal static class AsyncHelper { | |
private static readonly TaskFactory taskFactory = new TaskFactory(CancellationToken.None, TaskCreationOptions.None, TaskContinuationOptions.None, TaskScheduler.Default); | |
public static TResult RunSync<TResult>(this Func<Task<TResult>> func) { | |
return taskFactory.StartNew(func).Unwrap().GetAwaiter().GetResult(); | |
} | |
public static void RunSync(this Func<Task> func) { | |
taskFactory.StartNew(func).Unwrap().GetAwaiter().GetResult(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment