LCOV - code coverage report

Current view
top level - src/pool - _pool_worker.dart
Test
lcov.info
Date
2026-02-21
Legend
Lines
hit
not hit
Branches
taken
not taken
# not executed
HitTotalCoverage
Lines1818100.0%
Functions00-
Branches00-
Each row represents a line of source code
LineBranchHitsSource code
1import '../stats/worker_stat.dart';
2import '../worker/worker.dart';
3import '_worker_task.dart';
4import 'worker_pool.dart';
5
6/// Class representing a [Worker] from a [WorkerPool].
7class PoolWorker<W extends Worker> {
8 /// Constructs a new [PoolWorker].
94 PoolWorker(this.worker, this._maxWorkload) : _capacity = _maxWorkload;
10
11 /// The [Worker] associated to this [PoolWorker].
12 final W worker;
13
14 final int _maxWorkload;
15 int? _lastStart;
16 int _capacity;
17
18 static int _startSequence = 0;
19
20 /// The current capacity of this [PoolWorker].
218 int get capacity => _capacity;
22
23 /// Whether this [PoolWorker] is stopped or idle.
246 bool get isIdle => worker.isStopped || _capacity == _maxWorkload;
25
26 /// Whether this [PoolWorker] is stopped.
2712 bool get isStopped => worker.isStopped;
28
29 /// Run the specified [task] in the [worker].
304 Future<void> run(WorkerTask task) {
318 _lastStart = _startSequence++;
328 _capacity--;
3316 return task.run(worker).whenComplete(() {
348 _capacity++;
3512 if (_capacity == _maxWorkload) {
364 _lastStart = null;
37 }
38 });
39 }
40
41 /// Compares [PoolWorker] instances by capacity (descending) and last execution (ascending).
424 static int compareCapacity(PoolWorker a, PoolWorker b) {
4321 if (a.capacity != b.capacity) return a.capacity.compareTo(b.capacity);
4412 if (a._lastStart == b._lastStart) return 0;
452 if (a._lastStart == null) return -1;
462 if (b._lastStart == null) return 1;
476 return b._lastStart!.compareTo(a._lastStart!);
48 }
49
503 static WorkerStat getStats(PoolWorker w) => w.worker.getStats();
51}
Choose Features