Пример #1
0
 public AggregatedRequest(AggregatedRequestFunc <TRequestParam, TResponse> func, int aggregationTimeWindowMs, int maxDegreeOfAggregation)
 {
     _parameters             = new List <TRequestParam>();
     _func                   = func;
     AggregationTimeWindowMs = aggregationTimeWindowMs;
     MaxDegreeOfAggregation  = maxDegreeOfAggregation;
     Result                  = Execute();
 }
Пример #2
0
        public async Task <TResponse> Dispatch(AggregatedRequestFunc <TRequestParam, TResponse> requestFunc, TRequestParam parameter)
        {
            AggregatedRequest <TRequestParam, TResponse> request;

            lock (_syncRoot)
            {
                if (!_current.TryAppend(parameter))
                {
                    // can't join to current outgoing request, let's make a new one
                    _current = new AggregatedRequest <TRequestParam, TResponse>(requestFunc, _aggregationTimeWindow, _maxDegreeOfAggregation);
                    _current.Append(parameter);
                }
                // grab a reference to the current request
                request = _current;
            }

            var response = await request.Result;

            return(response[parameter]);
        }