LCOV - code coverage report

Current view
top level - src/pool - _worker_task.dart
Test
lcov.info
Date
2024-11-13
Legend
Lines
hit
not hit
Branches
taken
not taken
# not executed
HitTotalCoverage
Lines364580.0%
Functions00-
Branches00-
Each row represents a line of source code
LineBranchHitsSource code
1import 'dart:async';
2
3import '../_impl/xplat/_time_stamp.dart';
4import '../exceptions/task_canceled_exception.dart';
5import '../stats/perf_counter.dart';
6import '../worker/worker.dart';
7import 'task.dart';
8import 'worker_pool.dart';
9
10/// [WorkerTask] registered in the [WorkerPool].
11abstract base class WorkerTask<T, W extends Worker> implements Task<T> {
1212 WorkerTask(this._counter) : submitted = microsecTimeStamp();
13
14 final int submitted;
15 int? _scheduled;
16 int? _finished;
17 int? _canceled;
18
19 final PerfCounter? _counter;
20
21 final _done = Completer<void>();
22
23 /// Returns a future that will complete when the task has run.
241 @override
253 Future<void> get done => _done.future;
26
274 @override
288 bool get isCanceled => _canceled != null;
29
301 @override
313 bool get isPending => _scheduled == null && _canceled == null;
32
332 @override
342 bool get isFinished =>
358 _scheduled != null && _finished != null && _canceled == null;
36
372 @override
382 bool get isRunning =>
397 _scheduled != null && _finished == null && _canceled == null;
40
411 @override
422 Duration get runningTime => _scheduled == null
431 ? Duration.zero
440 : Duration(
45 microseconds:
461 (_canceled ?? _finished ?? microsecTimeStamp()) - _scheduled!);
47
480 @override
490 Duration get waitTime => Duration(
50 microseconds:
510 (_scheduled ?? _canceled ?? microsecTimeStamp()) - submitted);
52
53 TaskCanceledException? _canceledException;
546 TaskCanceledException? get canceledException => _canceledException;
55
564 void throwIfCanceled() {
578 if (_canceledException != null) throw _canceledException!;
58 }
59
602 @override
612 void cancel([String? message]) {
626 _canceled ??= microsecTimeStamp();
636 _canceledException ??= TaskCanceledException(message);
644 if (_scheduled == null) {
65 // task will not be scheduled, make sure it reports as completed
666 _done.complete();
67 }
682 }
69
708 void _success(bool res) {
7112 _finished ??= microsecTimeStamp();
7212 _counter?.update(_finished! - _scheduled!, res);
7312 _done.complete();
744 }
75
760 void _error(_) {
770 _finished ??= microsecTimeStamp();
780 _counter?.update(_finished! - _scheduled!, false);
790 _done.complete();
800 }
81
828 Future<void> run(W worker) async {
8312 _scheduled ??= microsecTimeStamp();
84
8520 return execute(worker).then(_success, onError: _error);
864 }
87
88 Future<bool> execute(W worker);
89}
Choose Features