LCOV - code coverage report

Current view
top level - src/pool - _pool_worker.dart
Test
lcov.info
Date
2026-11-07
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].
91 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].
212 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.
273 bool get isStopped => worker.isStopped;
28
29 /// Run the specified [task] in the [worker].
301 Future<void> run(WorkerTask task) {
312 _lastStart = _startSequence++;
322 _capacity--;
334 return task.run(worker).whenComplete(() {
342 _capacity++;
353 if (_capacity == _maxWorkload) {
361 _lastStart = null;
37 }
38 });
39 }
40
41 /// Compares [PoolWorker] instances by capacity (descending) and last execution (ascending).
421 static int compareCapacity(PoolWorker a, PoolWorker b) {
436 if (a.capacity != b.capacity) return a.capacity.compareTo(b.capacity);
443 if (a._lastStart == b._lastStart) return 0;
451 if (a._lastStart == null) return -1;
461 if (b._lastStart == null) return 1;
473 return b._lastStart!.compareTo(a._lastStart!);
48 }
49
503 static WorkerStat getStats(PoolWorker w) => w.worker.getStats();
51}
Choose Features