LCOV - code coverage report

Current view
top level - src/pool - _worker_value_task.dart
Test
lcov.info
Date
2024-11-13
Legend
Lines
hit
not hit
Branches
taken
not taken
# not executed
HitTotalCoverage
Lines2626100.0%
Functions00-
Branches00-
Each row represents a line of source code
LineBranchHitsSource code
1import 'dart:async';
2
3import '../exceptions/squadron_exception.dart';
4import '../stats/perf_counter.dart';
5import '../worker/worker.dart';
6import '_worker_task.dart';
7import 'value_task.dart';
8
9final class WorkerValueTask<T, W extends Worker> extends WorkerTask<T, W>
10 implements ValueTask<T> {
11 /// Creates a new [ValueTask].
129 WorkerValueTask(this._computer, PerfCounter? counter) : super(counter);
13
14 final Future<T> Function(W worker) _computer;
15 final _result = Completer<T>();
16
173 @override
189 Future<T> get value => _result.future;
19
204 void _failure(SquadronException exception) {
216 if (!_result.isCompleted) {
226 _result.completeError(exception);
23 }
242 }
25
263 void _success(dynamic data) {
279 if (!_result.isCompleted) {
289 _result.complete(data);
29 }
30 }
31
322 @override
332 void cancel([String? message]) {
344 super.cancel(message);
356 _failure(canceledException!);
362 }
37
383 @override
393 Future<bool> execute(W worker) async {
403 try {
413 throwIfCanceled();
429 final res = await _computer(worker);
433 _success(res);
443 return true;
451 } catch (ex, st) {
463 _failure(SquadronException.from(ex, st));
471 return false;
48 }
493 }
50}
Choose Features