public Task <IEnumerable <T> > LoadAsync(TKey key) { lock (_cache) { // Get value from the cache if it's there if (_cache.TryGetValue(key, out var value)) { return(Task.FromResult(value)); } // Otherwise add to pending keys _pendingKeys.Add(key); } // Return task which will complete when this loader is dispatched return(DataLoaded.ContinueWith(task => task.Result[key], TaskContinuationOptions.OnlyOnRanToCompletion)); }