mirror of
https://github.com/AlexMacocian/SystemExtensions.git
synced 2026-07-24 03:56:27 +00:00
Update dependencies (#16)
* Update dependencies Implement AsyncLazy Fix namespaces Fix CD pipeline * Fix code issues Fix Int64BitStruct test
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace System;
|
||||
|
||||
/// <summary>
|
||||
/// Async implementation of <see cref="Lazy{T}"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Credits: https://devblogs.microsoft.com/pfxteam/asynclazyt/
|
||||
/// </remarks>
|
||||
/// <typeparam name="T">Type of value to be returned.</typeparam>
|
||||
public sealed class AsyncLazy<T> : Lazy<Task<T>>
|
||||
{
|
||||
public TaskAwaiter<T> GetAwaiter() => this.Value.GetAwaiter();
|
||||
|
||||
public AsyncLazy(Func<T> valueFactory)
|
||||
: base(() => Task.Factory.StartNew(valueFactory))
|
||||
{
|
||||
}
|
||||
|
||||
public AsyncLazy(Func<Task<T>> taskFactory)
|
||||
: base(() => Task.Factory.StartNew(() => taskFactory()).Unwrap())
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user