public BatchEventAggregator(int minimumBatchSeparationInMilliseconds, IEventSchedulerFactory schedulerFactory, ITimer timer) { _minimumBatchSeparationInMilliseconds = minimumBatchSeparationInMilliseconds; _scheduler = schedulerFactory.Create(HandleBatchCheck); _currentBatchAndTimerLocker = new object(); _currentBatch = new TBatch(); _timer = timer; }
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()); }