LCOV - code coverage report

Current view
top level - src/tokens - _squadron_cancelation_token.dart
Test
lcov.info
Date
2024-11-13
Legend
Lines
hit
not hit
Branches
taken
not taken
# not executed
HitTotalCoverage
Lines364090.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 {
104 SquadronCancelationToken._(this.token, this.id) {
1110 token?.onCanceled.then(_checkToken);
120 }
13
142 List serialize() {
154 _checkToken();
166 return List.unmodifiable([
174 id,
186 exception?.serialize(),
19 ]);
200 }
21
2210 static SquadronCancelationToken? deserialize(List? props) {
231 if (props == null) return null;
242 final id = props[_$id];
254 final ex = SquadronCanceledExceptionExt.deserialize(props[_$ex]);
262 final token = SquadronCancelationToken._(null, id);
270 if (ex != null) {
282 token._exception = ex;
294 token._completer.complete(ex);
30 }
310 return token;
321 }
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
424 SquadronCanceledException? get exception => _exception;
43 SquadronCanceledException? _exception;
44
452 @override
462 void ensureStarted() {
475 token?.ensureStarted();
482 }
49
502 @override
516 Future<CanceledException> get onCanceled => _completer.future;
52 final _completer = Completer<CanceledException>();
53
544 void _checkToken([dynamic _]) {
556 final ex = token?.exception;
562 if (ex != null) {
578 _exception ??= SquadronCanceledException.from(id, ex);
586 if (!_completer.isCompleted) {
598 _completer.complete(_exception);
60 }
61 }
622 }
63}
64
65const _$id = 0;
66const _$ex = 1;
67
68@internal
69extension SquadronCancelationTokenExt on CancelationToken {
704 SquadronCancelationToken wrap() {
71 final self = this;
722 if (self is SquadronCancelationToken) return self;
734 final token = SquadronCancelationToken._(self, TokenId.next());
744 token._checkToken();
752 return token;
762 }
77}
Choose Features