Hit | Total | Coverage | |
---|---|---|---|
Lines | 15 | 17 | 88.2% |
Functions | 0 | 0 | - |
Branches | 0 | 0 | - |
Line | Branch | Hits | Source code |
---|---|---|---|
1 | import 'dart:async'; |
||
2 |
|
||
3 | class EventBuffer<T> { |
||
4 | 9 | EventBuffer(this._processValue, this._processError); |
|
5 |
|
||
6 | 0 | FutureOr<void> Function()? onDeactivate; |
|
7 |
|
||
8 | final void Function(T) _processValue; |
||
9 | final void Function(Object, StackTrace?) _processError; |
||
10 |
|
||
11 | 9 | final _buffer = <void Function()>[]; |
|
12 |
|
||
13 | var _pauses = 0; |
||
14 |
|
||
15 | 10 | bool get isActive => _pauses > 0; |
|
16 |
|
||
17 | 2 | void activate() => _pauses++; |
|
18 |
|
||
19 | 2 | void deactivate() { |
|
20 | 2 | if (_pauses == 1) { |
|
21 | 2 | for (var fn in _buffer) { |
|
22 | 2 | fn.call(); |
|
23 | } |
||
24 | 2 | _buffer.clear(); |
|
25 | 2 | onDeactivate?.call(); |
|
26 | } |
||
27 | 2 | if (_pauses > 0) { |
|
28 | 2 | _pauses--; |
|
29 | } |
||
30 | 2 | } |
|
31 |
|
||
32 | 9 | void add(T value) => _buffer.add(() => _processValue(value)); |
|
33 |
|
||
34 | 0 | void addError(Object err, StackTrace? st) => |
|
35 | 9 | _buffer.add(() => _processError(err, st)); |
|
36 | } |