From bca37228d906c9e9d83761785ba763568483b60e Mon Sep 17 00:00:00 2001 From: Fre Date: Fri, 21 Aug 2020 12:22:28 +0200 Subject: [PATCH] del asynchelper --- ElectronNET.API/AsyncHelper.cs | 46 ---------------------------------- 1 file changed, 46 deletions(-) delete mode 100644 ElectronNET.API/AsyncHelper.cs diff --git a/ElectronNET.API/AsyncHelper.cs b/ElectronNET.API/AsyncHelper.cs deleted file mode 100644 index 8feeea6..0000000 --- a/ElectronNET.API/AsyncHelper.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; -using System.Threading; -using System.Threading.Tasks; - -namespace ElectronNET.API -{ - internal static class AsyncHelper - { - private static readonly TaskFactory _taskFactory = new - TaskFactory(CancellationToken.None, - TaskCreationOptions.None, - TaskContinuationOptions.None, - TaskScheduler.Default); - - public static TResult RunSync(Func> func) - => _taskFactory - .StartNew(func) - .Unwrap() - .GetAwaiter() - .GetResult(); - - public static void RunSync(Func func) - => _taskFactory - .StartNew(func) - .Unwrap() - .GetAwaiter() - .GetResult(); - - public static async Task TimeoutAfter(this Task task, TimeSpan timeout) - { - using (var timeoutCancellationTokenSource = new CancellationTokenSource()) - { - var completedTask = await Task.WhenAny(task, Task.Delay(timeout, timeoutCancellationTokenSource.Token)); - if (completedTask == task) - { - timeoutCancellationTokenSource.Cancel(); - return await task; // Very important in order to propagate exceptions - } - else - { - throw new TimeoutException($"{nameof(TimeoutAfter)}: The operation has timed out after {timeout:mm\\:ss}"); - } - } - } - } -}