33// BSD-style license that can be found in the LICENSE file.
44
55import 'dart:async' ;
6+ import 'dart:math' ;
67import 'package:async/async.dart' ;
78import 'package:dwds/src/utilities/shared.dart' ;
89
910/// Stream controller allowing to batch events.
1011class BatchedStreamController <T > {
1112 static const _defaultBatchDelayMilliseconds = 1000 ;
12- static const _checkDelayMilliseconds = 100 ;
1313
14+ final int _checkDelayMilliseconds;
1415 final int _batchDelayMilliseconds;
1516
1617 final StreamController <T > _inputController;
@@ -26,6 +27,7 @@ class BatchedStreamController<T> {
2627 BatchedStreamController ({
2728 int delay = _defaultBatchDelayMilliseconds,
2829 }) : _batchDelayMilliseconds = delay,
30+ _checkDelayMilliseconds = max (delay ~ / 10 , 1 ),
2931 _inputController = StreamController <T >(),
3032 _outputController = StreamController <List <T >>() {
3133 _inputQueue = StreamQueue <T >(_inputController.stream);
@@ -46,7 +48,7 @@ class BatchedStreamController<T> {
4648
4749 /// Send events to the output in a batch every [_batchDelayMilliseconds] .
4850 Future <void > _batchAndSendEvents () async {
49- const duration = Duration (milliseconds: _checkDelayMilliseconds);
51+ final duration = Duration (milliseconds: _checkDelayMilliseconds);
5052 final buffer = < T > [];
5153
5254 // Batch events every `_batchDelayMilliseconds`.
0 commit comments