LCOV - code coverage report

Current view
top level - src/pool - _pool_worker.dart
Test
lcov.info
Date
2025-07-05
Legend
Lines
hit
not hit
Branches
taken
not taken
# not executed
HitTotalCoverage
Lines1717100.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 /// The current capacity of this [PoolWorker].
198 int get capacity => _capacity;
20
21 /// Whether this [PoolWorker] is stopped or idle.
226 bool get isIdle => worker.isStopped || _capacity == _maxWorkload;
23
24 /// Whether this [PoolWorker] is stopped.
2512 bool get isStopped => worker.isStopped;
26
27 /// Run the specified [task] in the [worker].
284 Future<void> run(WorkerTask task) {
2912 _lastStart = DateTime.now().millisecondsSinceEpoch;
308 _capacity--;
3116 return task.run(worker).whenComplete(() {
328 _capacity++;
3312 if (_capacity == _maxWorkload) {
344 _lastStart = null;
35 }
36 });
37 }
38
39 /// Compares [PoolWorker] instances by capacity (descending) and last execution (ascending).
404 static int compareCapacity(PoolWorker a, PoolWorker b) {
4121 if (a.capacity != b.capacity) return a.capacity.compareTo(b.capacity);
428 if (a._lastStart == null) return -1;
432 if (b._lastStart == null) return 1;
446 return b._lastStart!.compareTo(a._lastStart!);
45 }
46
473 static WorkerStat getStats(PoolWorker w) => w.worker.getStats();
48}
Choose Features