LCOV - code coverage report

Current view
top level - src/tokens - _squadron_cancelation_token.dart
Test
lcov.info
Date
2026-11-07
Legend
Lines
hit
not hit
Branches
taken
not taken
# not executed
HitTotalCoverage
Lines2828100.0%
Functions00-
Branches00-
Each row represents a line of source code
LineBranchHitsSource code
1import 'dart:async';
2
3import 'package:cancelation_token/cancelation_token.dart';
4import 'package:meta/meta.dart';
5
6import '../_impl/xplat/_token_id.dart';
7import '../exceptions/squadron_canceled_exception.dart';
8
9class SquadronCancelationToken extends CancelationToken {
101 SquadronCancelationToken._(this.token, this.id) {
114 token?.onCanceled.then(_checkToken);
12 }
13
141 List serialize() {
151 _checkToken();
162 return List.unmodifiable([
171 id,
182 exception?.serialize(),
19 ]);
20 }
21
221 static SquadronCancelationToken? deserialize(List? props) {
23 if (props == null) return null;
241 final id = props[_$id];
252 final ex = SquadronCanceledExceptionExt.deserialize(props[_$ex]);
261 final token = SquadronCancelationToken._(null, id);
27 if (ex != null) {
281 token._exception = ex;
292 token._completer.complete(ex);
30 }
31 return token;
32 }
33
34 // cancelation token ID
35 final String id;
36
37 // reference to the real cancelation token (only set on the caller side, will
38 // be `null` in worker threads)
39 final CancelationToken? token;
40
411 @override
421 SquadronCanceledException? get exception => _exception;
43 SquadronCanceledException? _exception;
44
451 @override
46 void ensureStarted() {
472 token?.ensureStarted();
48 }
49
501 @override
512 Future<CanceledException> get onCanceled => _completer.future;
52 final _completer = Completer<CanceledException>();
53
541 void _checkToken([dynamic _]) {
552 final ex = token?.exception;
56 if (ex != null) {
573 _exception ??= SquadronCanceledException.from(id, ex);
582 if (!_completer.isCompleted) {
593 _completer.complete(_exception);
60 }
61 }
62 }
63}
64
65const _$id = 0;
66const _$ex = 1;
67
68@internal
69extension SquadronCancelationTokenExt on CancelationToken {
701 SquadronCancelationToken wrap() {
71 final self = this;
721 if (self is SquadronCancelationToken) return self;
732 final token = SquadronCancelationToken._(self, TokenId.next());
741 token._checkToken();
75 return token;
76 }
77}
Choose Features