LCOV - code coverage report

Current view
top level - src/tokens - _squadron_cancelation_token.dart
Test
lcov.info
Date
2025-03-26
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 {
102 SquadronCancelationToken._(this.token, this.id) {
118 token?.onCanceled.then(_checkToken);
12 }
13
142 List serialize() {
152 _checkToken();
164 return List.unmodifiable([
172 id,
184 exception?.serialize(),
19 ]);
20 }
21
2210 static SquadronCancelationToken? deserialize(List? props) {
23 if (props == null) return null;
242 final id = props[_$id];
254 final ex = SquadronCanceledExceptionExt.deserialize(props[_$ex]);
262 final token = SquadronCancelationToken._(null, id);
27 if (ex != null) {
282 token._exception = ex;
294 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
412 @override
422 SquadronCanceledException? get exception => _exception;
43 SquadronCanceledException? _exception;
44
452 @override
46 void ensureStarted() {
474 token?.ensureStarted();
48 }
49
502 @override
514 Future<CanceledException> get onCanceled => _completer.future;
52 final _completer = Completer<CanceledException>();
53
542 void _checkToken([dynamic _]) {
554 final ex = token?.exception;
56 if (ex != null) {
576 _exception ??= SquadronCanceledException.from(id, ex);
584 if (!_completer.isCompleted) {
596 _completer.complete(_exception);
60 }
61 }
62 }
63}
64
65const _$id = 0;
66const _$ex = 1;
67
68@internal
69extension SquadronCancelationTokenExt on CancelationToken {
702 SquadronCancelationToken wrap() {
71 final self = this;
722 if (self is SquadronCancelationToken) return self;
734 final token = SquadronCancelationToken._(self, TokenId.next());
742 token._checkToken();
75 return token;
76 }
77}
Choose Features