-
Notifications
You must be signed in to change notification settings - Fork 1
/
AsyncLazy.cs
31 lines (30 loc) · 930 Bytes
/
AsyncLazy.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Grammophone.Caching
{
/// <summary>
/// Provides support for asynchronous lazy initialization.
/// </summary>
/// <typeparam name="T">The type of object being lazily initialized.</typeparam>
public class AsyncLazy<T> : Lazy<Task<T>>
{
/// <summary>
/// Create.
/// </summary>
/// <param name="asyncValueFactory">
/// An asynchronous function to produce the value when it is needed.
/// </param>
/// <param name="isThreadSafe">
/// If true, makes the instance usable concurrently by multiple threads.
/// Set to false when high performance is crucial and the instance is guaranteed to be
/// accessed by one thread at a time.
/// </param>
public AsyncLazy(Func<Task<T>> asyncValueFactory, bool isThreadSafe = true)
: base(asyncValueFactory, isThreadSafe)
{
}
}
}