Skip to content

Commit d442fa8

Browse files
author
Anna Gringauze
authored
Check for new events more often in batched stream. (#2123)
* Make wait time for events to batch depend on batch time * Update changelog
1 parent 4b69f1d commit d442fa8

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

dwds/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- Refactor code for presenting record instances. - [#2074](https://github.com/dart-lang/webdev/pull/2074)
55
- Display record types concisely. - [#2070](https://github.com/dart-lang/webdev/pull/2070)
66
- Display type objects concisely. - [#2103](https://github.com/dart-lang/webdev/pull/2103)
7+
- Check for new events more often in batched stream. - [#2123](https://github.com/dart-lang/webdev/pull/2123)
78

89
## 19.0.0
910

dwds/lib/shared/batched_stream.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'dart:async';
6+
import 'dart:math';
67
import 'package:async/async.dart';
78
import 'package:dwds/src/utilities/shared.dart';
89

910
/// Stream controller allowing to batch events.
1011
class 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

Comments
 (0)