Example #1
0
        private async Task DispatchAsync(
            TKey resolvedKey,
            TaskCompletionSource <TValue> promise)
        {
            var      resolvedKeys = new TKey[] { resolvedKey };
            Activity activity     = DispatchingDiagnostics
                                    .StartBatching(resolvedKeys);
            IReadOnlyList <IResult <TValue> > results =
                await Fetch(resolvedKeys).ConfigureAwait(false);

            if (results.Count == 1)
            {
                SetSingleResult(promise, resolvedKey, results.First());
            }
            else
            {
                Exception error = Errors.CreateKeysAndValuesMustMatch(1,
                                                                      results.Count);

                DispatchingDiagnostics.RecordError(resolvedKey, error);
                promise.SetException(error);
            }

            DispatchingDiagnostics.StopBatching(activity, resolvedKeys,
                                                results);
        }
Example #2
0
        private async Task FetchInternalAsync(
            IDictionary <TKey, TaskCompletionSource <TValue> > bufferedPromises,
            IReadOnlyList <TKey> resolvedKeys)
        {
            Activity activity = DispatchingDiagnostics
                                .StartBatching(resolvedKeys);
            IReadOnlyList <IResult <TValue> > results =
                await Fetch(resolvedKeys).ConfigureAwait(false);

            SetBatchResults(bufferedPromises, resolvedKeys, results);
            DispatchingDiagnostics.StopBatching(activity, resolvedKeys,
                                                results);
        }