LCOV - code coverage report

Current view
top level - src/pool - _pool_worker.dart
Test
lcov.info
Date
2025-03-26
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 doing nothing.
227 bool get isIdle => worker.stats.isStopped || _capacity == _maxWorkload;
23
24 /// Run the specified [task] in the [worker].
254 Future<void> run(WorkerTask task) {
2612 _lastStart = DateTime.now().millisecondsSinceEpoch;
278 _capacity--;
2816 return task.run(worker).whenComplete(() {
298 _capacity++;
3012 if (_capacity == _maxWorkload) {
314 _lastStart = null;
32 }
33 });
34 }
35
36 /// Compares [PoolWorker] instances by capacity (descending) and last execution (ascending).
374 static int compareCapacityDesc(PoolWorker a, PoolWorker b) {
3824 if (a.capacity != b.capacity) return b.capacity.compareTo(a.capacity);
393 if (a._lastStart == null) return 1;
403 if (b._lastStart == null) return -1;
419 return a._lastStart!.compareTo(b._lastStart!);
42 }
43
4416 static bool isStopped(PoolWorker w) => w.worker.stats.isStopped;
453 static WorkerStat getStats(PoolWorker w) => w.worker.stats;
46}
Choose Features