/// <summary> /// Creates a <see cref="Task"/> using the <c>Task.FromResult</c> method, but caches the result for the next call. /// </summary> /// <param name="value">The value.</param> /// <returns>Task<T>.</returns> public static Task <T> FromResult(T value) { lock (_fromResultCache) { if (!_fromResultCache.TryGetValue(value, out var task)) { task = TaskShim.FromResult(value); _fromResultCache[value] = task; } return(task); } }
/// <summary> /// Creates a <see cref="Task"/> using the <c>Task.FromResult</c> method, but caches the result for the next call. /// </summary> /// <param name="value">The value.</param> /// <returns>Task<T>.</returns> public static Task <T> FromResult(T value) { Task <T> task; if (!_fromResultCache.ContainsKey(value)) { task = TaskShim.FromResult(value); _fromResultCache[value] = task; } else { task = _fromResultCache[value]; } return(task); }
/// <summary> /// Creates a new async-compatible mutual exclusion lock using the specified wait queue. /// </summary> /// <param name="queue">The wait queue used to manage waiters.</param> public AsyncLock(IAsyncWaitQueue <IDisposable> queue) { _queue = queue; _cachedKeyTask = TaskShim.FromResult <IDisposable>(new Key(this)); _mutex = new object(); }