Exemple #1
0
        private void SetBatchResults(
            IDictionary <TKey, TaskCompletionSource <TValue> > bufferedPromises,
            IReadOnlyList <TKey> resolvedKeys,
            IReadOnlyList <IResult <TValue> > results)
        {
            if (resolvedKeys.Count == results.Count)
            {
                for (var i = 0; i < resolvedKeys.Count; i++)
                {
                    SetSingleResult(bufferedPromises[resolvedKeys[i]],
                                    resolvedKeys[i], results[i]);
                }
            }
            else
            {
                Exception error = Errors.CreateKeysAndValuesMustMatch(
                    resolvedKeys.Count, results.Count);

                for (var i = 0; i < resolvedKeys.Count; i++)
                {
                    DispatchingDiagnostics.RecordError(resolvedKeys[i], error);
                    bufferedPromises[resolvedKeys[i]].SetException(error);
                }
            }
        }
Exemple #2
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);
        }
Exemple #3
0
 private void SetSingleResult(
     TaskCompletionSource <TValue> promise,
     TKey resolvedKey,
     IResult <TValue> result)
 {
     if (result.IsError)
     {
         DispatchingDiagnostics.RecordError(resolvedKey, result.Error);
         promise.SetException(result.Error);
     }
     else
     {
         promise.SetResult(result.Value);
     }
 }