-
-
Notifications
You must be signed in to change notification settings - Fork 353
/
TaskHelper.cs
33 lines (31 loc) · 1 KB
/
TaskHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
using System.Threading.Tasks;
namespace Nito.AsyncEx
{
/// <summary>
/// Helper methods for working with tasks.
/// </summary>
public static class TaskHelper
{
/// <summary>
/// Executes a delegate synchronously, and captures its result in a task. The returned task is already completed.
/// </summary>
/// <param name="func">The delegate to execute synchronously.</param>
#pragma warning disable 1998
public static async Task ExecuteAsTask(Action func)
#pragma warning restore 1998
{
func();
}
/// <summary>
/// Executes a delegate synchronously, and captures its result in a task. The returned task is already completed.
/// </summary>
/// <param name="func">The delegate to execute synchronously.</param>
#pragma warning disable 1998
public static async Task<T> ExecuteAsTask<T>(Func<T> func)
#pragma warning restore 1998
{
return func();
}
}
}