LCOV - code coverage report

Current view
top level - src/pool - _pool_worker.dart
Test
lcov.info
Date
2024-11-13
Legend
Lines
hit
not hit
Branches
taken
not taken
# not executed
HitTotalCoverage
Lines2020100.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].
98 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].
1912 int get capacity => _capacity;
20
21 /// Whether this [PoolWorker] is stopped or doing nothing.
227 bool get isIdle => worker.isStopped || _capacity == _maxWorkload;
23
24 /// Run the specified [task] in the [worker].
258 Future<void> run(WorkerTask task) {
2616 _lastStart = DateTime.now().millisecondsSinceEpoch;
278 _capacity--;
2820 return task.run(worker).whenComplete(() {
2912 _capacity++;
3016 if (_capacity == _maxWorkload) {
318 _lastStart = null;
32 }
334 });
344 }
35
36 /// Compares [PoolWorker] instances by capacity (descending) and last execution (ascending).
376 static int compareCapacityDesc(PoolWorker a, PoolWorker b) {
3821 if (a.capacity != b.capacity) return b.capacity.compareTo(a.capacity);
396 if (a._lastStart == null) return 1;
406 if (b._lastStart == null) return -1;
4112 return a._lastStart!.compareTo(b._lastStart!);
423 }
43
4416 static bool isStopped(PoolWorker w) => w.worker.isStopped;
454 static WorkerStat getStats(PoolWorker w) => w.worker.stats;
46}
Choose Features