Example #1
0
        private async Task FetchInternalAsync(
            IDictionary <TKey, TaskCompletionSource <TValue> > bufferedPromises,
            IReadOnlyList <TKey> keys,
            CancellationToken cancellationToken)
        {
            Activity activity = DiagnosticEvents
                                .StartBatching(keys);
            IReadOnlyList <Result <TValue> > results = new Result <TValue> [0];

            try
            {
                results = await FetchAsync(keys, cancellationToken)
                          .ConfigureAwait(false);

                BatchOperationSucceeded(bufferedPromises, keys,
                                        results);
            }
            catch (Exception ex)
            {
                BatchOperationFailed(bufferedPromises, keys, ex);
            }

            DiagnosticEvents.StopBatching(activity, keys,
                                          results.Select(r => r.Value).ToArray());
        }
Example #2
0
        private ValueTask DispatchBatchAsync(
            Batch <TKey, TValue> batch,
            CancellationToken cancellationToken)
        {
            return(batch.StartDispatchingAsync(async() =>
            {
                Activity?activity = DiagnosticEvents.StartBatching(batch.Keys);
                IReadOnlyList <Result <TValue> > results = Array.Empty <Result <TValue> >();

                try
                {
                    results = await FetchAsync(batch.Keys, cancellationToken).ConfigureAwait(false);
                    BatchOperationSucceeded(batch, batch.Keys, results);
                }
                catch (Exception ex)
                {
                    BatchOperationFailed(batch, batch.Keys, ex);
                }

                DiagnosticEvents.StopBatching(activity, batch.Keys,
                                              results.Select(result => result.Value).ToArray());
            }));
        }