private static async Task RunConsumer(AsyncEventStream <Event> stream)
    {
        var aggregations = new Dictionary <int, (double sum, int count)>();

        try
        {
            await foreach (var batch in stream.ConfigureAwait(false))
            {
                foreach (var evt in batch)
                {
                    var aggregation = aggregations.GetValueOrDefault(evt.Id);

                    aggregations[evt.Id] = (aggregation.sum + evt.Price, aggregation.count + 1);
                }
            }
        }
        catch (OperationCanceledException)
        {
            Console.WriteLine($"Consumer iteration cancelled");
        }

        Console.WriteLine($"EventCount: {aggregations.Sum(x => x.Value.count)}");

        foreach (var(id, aggregation) in aggregations.OrderBy(x => x.Key))
        {
            Console.WriteLine($"Id: {id}, Average: {aggregation.sum / aggregation.count:N2}");
        }
    }
        public Enumerator(AsyncEventStream <T> asyncEventStream, Sequence sequence, CancellationToken streamCancellationToken, CancellationToken enumeratorCancellationToken)
        {
            _asyncEventStream  = asyncEventStream;
            _sequence          = sequence;
            _linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(streamCancellationToken, enumeratorCancellationToken);

            _cancellationTokenRegistration = _linkedTokenSource.Token.Register(x => ((IAsyncWaitStrategy)x !).SignalAllWhenBlocking(), asyncEventStream._waitStrategy);
        }
Exemplo n.º 3
0
 public StreamProcessor(AsyncEventStream <PerfEvent> stream)
 {
     _stream = stream;
 }