2017-02-20 22:46:34 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2017-07-17 19:42:36 +00:00
|
|
|
|
namespace NadekoBot.Common
|
2017-02-20 22:46:34 +00:00
|
|
|
|
{
|
|
|
|
|
public class AsyncLazy<T> : Lazy<Task<T>>
|
|
|
|
|
{
|
|
|
|
|
public AsyncLazy(Func<T> valueFactory) :
|
|
|
|
|
base(() => Task.Factory.StartNew(valueFactory))
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
public AsyncLazy(Func<Task<T>> taskFactory) :
|
|
|
|
|
base(() => Task.Factory.StartNew(taskFactory).Unwrap())
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
public TaskAwaiter<T> GetAwaiter() { return Value.GetAwaiter(); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|