/// <summary> /// Loads some data corresponding to the given key. /// </summary> /// <remarks> /// Each requested key is collected into a batch so that they can be fetched in a single call. /// When data for a key is loaded, it will be cached and used to fulfil any subsequent requests for the same key. /// </remarks> public Task <TReturn> LoadAsync(TKey key) { lock (_lock) { if (_cache.TryGetValue(key, out var task)) { return(task); } _batch.Add(key); return(_cache[key] = Completion.ContinueWith( SelectKeyFromTaskResult , key , CancellationToken.None , TaskContinuationOptions.None , TaskScheduler.Default)); } }
/// <summary> /// Loads some data corresponding to the given key. /// </summary> /// <remarks> /// Each requested key is collected into a batch so that they can be fetched in a single call. /// When data for a key is loaded, it will be cached and used to fulfil any subsequent requests for the same key. /// </remarks> /// <returns>The future result matching the given key.</returns> public Task <IEnumerable <TReturn> > LoadAsync(TKey key) { ThrowIfDisposed(); lock (_lock) { if (_cache.TryGetValue(key, out var task)) { return(task); } _batch.Add(key); return(_cache[key] = Completion.ContinueWith( (t, state) => t.Result[(TKey)state] , key , CancellationToken.None , TaskContinuationOptions.None , TaskScheduler.Default)); } }
public void Dispose() { Complete(); Completion.ContinueWith(t => { /* Ignore fault */ }).Wait(); }