Created
May 23, 2021 11:49
-
-
Save dimonovdd/e9370f204ef45aa1777dad7d6ccab665 to your computer and use it in GitHub Desktop.
RunSyncUtil
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
using System; | |
using System.Threading.Tasks; | |
namespace Sync | |
{ | |
public static class RunSyncUtil | |
{ | |
private static readonly TaskFactory factory = new | |
TaskFactory(default, | |
TaskCreationOptions.None, | |
TaskContinuationOptions.None, | |
TaskScheduler.Default); | |
public static T1 RunSync<T1>(Func<Task<T1>> task) | |
=> factory.StartNew(task).Unwrap().GetAwaiter().GetResult(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment