LCOV - code coverage report

Current view
top level - /src - cancellable_token.dart
Test
lcov.info
Date
2022-04-02
Legend
Lines
hit
not hit
Branches
taken
not taken
# not executed
HitTotalCoverage
Lines222395.7%
Functions00-
Branches00-
Each row represents a line of source code
LineBranchHitsSource code
1import 'cancellation_token.dart';
2import '_sequence_id.dart';
3import 'squadron.dart';
4import 'worker_exception.dart';
5import 'worker_service.dart' show SquadronCallback;
6
72void _safeInvoke(SquadronCallback? callback) {
81 try {
91 if (callback != null) {
102 callback();
11 }
12 } catch (e) {
130 Squadron.warning('notification to listener $callback failed: $e');
14 }
151}
16
17/// Base class for cancellation tokens used by callers of worker services. It implements the logic to register,
18/// notify and unregister token listeners. This cancellation token can be cancelled programmatically by calling
19/// [cancel].
20class CancellableToken extends CancellationToken {
211 CancellableToken([String? message])
224 : super(SequenceId.instance.next(), message);
23
241 @override
252 CancelledException? get exception => _exception;
26 CancelledException? _exception;
27
282 void setException(CancelledException exception) {
292 _exception ??= exception;
304 _listeners?.toList().forEach(_safeInvoke);
311 }
32
33 /// Cancels the token and notifies listeners.
342 void cancel() =>
355 setException(_exception ?? CancelledException(message: message));
36
371 List<SquadronCallback>? _listeners;
38
39 /// Registers a listener that will be notified when the token is cancelled.
401 @override
411 void addListener(SquadronCallback listener) =>
425 _listeners = (_listeners ?? <SquadronCallback>[])..add(listener);
43
441 @override
451 void removeListener(SquadronCallback listener) =>
463 _listeners?.remove(listener);
47}
Choose Features