Created
August 24, 2017 21:26
-
-
Save dcomartin/722fa02a65c07b549781d421d1a88d26 to your computer and use it in GitHub Desktop.
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
/// <summary> | |
/// Provides support for asynchronous lazy initialization. | |
/// </summary> | |
/// <typeparam name="T"></typeparam> | |
public class LazyAsync<T> : Lazy<Task<T>> | |
{ | |
/// <summary> | |
/// Initializes a new instance of the LazyAsync`1 class. When lazy initialization | |
/// occurs, the specified initialization function is used. | |
/// </summary> | |
/// <param name="taskFunc">The delegate that is invoked to produce the lazily initialized Task when it is needed.</param> | |
public LazyAsync(Func<Task<T>> taskFunc) : | |
base(() => Task.Factory.StartNew(taskFunc).Unwrap()) { } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment