Created
September 9, 2017 09:28
-
-
Save idiotandrobot/781c9fc686c9868efcc64b0e3e8e3b75 to your computer and use it in GitHub Desktop.
AsyncLazy<T> v1
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
// https://blogs.msdn.microsoft.com/pfxteam/2011/01/15/asynclazyt/ | |
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(); } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment