Example #1
0
        public BatchEventAggregator(int minimumBatchSeparationInMilliseconds,
                                    IEventSchedulerFactory schedulerFactory, ITimer timer)
        {
            _minimumBatchSeparationInMilliseconds = minimumBatchSeparationInMilliseconds;
            _scheduler = schedulerFactory.Create(HandleBatchCheck);

            _currentBatchAndTimerLocker = new object();
            _currentBatch = new TBatch();
            _timer        = timer;
        }
Example #2
0
        void HandleBatchCheck()
        {
            IEventBatch <TParams, TSummary> finalizedBatch;

            lock (_currentBatchAndTimerLocker)
            {
                if (_timer.ElapsedMilliseconds < _minimumBatchSeparationInMilliseconds)
                {
                    return;
                }

                finalizedBatch = _currentBatch;
                _currentBatch  = new TBatch();
                _timer.Reset();
            }
            BatchSummaryReady?.Invoke(this, finalizedBatch.GetSummary());
        }