WorkerPool<W extends Worker> class

Worker pool responsible for instantiating, starting and stopping workers running in parallel. A WorkerPool is also responsible for creating and assigning WorkerTasks to Workers.

Implemented types

Constructors

WorkerPool(WorkerFactory<W> _workerFactory, {ConcurrencySettings? concurrencySettings})
Create a worker pool.

Properties

concurrencySettings ConcurrencySettings
Concurrency settings.
final
fullStats Iterable<WorkerStat>
Full worker statistics.
no setter
hashCode int
The hash code for this object.
no setterinherited
maxConcurrency int
Maximum running tasks.
no setter
maxParallel int
Maximum tasks per worker.
no setter
maxSize int
Maximum number of workers.
no setter
maxWorkers int
Maximum workers.
no setter
maxWorkload int
Maximum workload.
no setter
minWorkers int
Minimum workers.
no setter
operations Map<int, CommandHandler>
Worker pools do not need an operations map.
no setteroverride
pendingWorkload int
Gets remaining workload
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
size int
Number of workers.
no setter
stats Iterable<WorkerStat>
Worker statistics.
no setter
stopped bool
Whether this pool is scheduled for stopping.
no setter
totalErrors int
Number of errors.
no setter
totalWorkload int
Total workload.
no setter
workload int
Current workload.
no setter

Methods

cancel([Task? task, String? message]) → void
Task cancellation. If a specific task is provided, only this task will be cancelled. Otherwise, all tasks registered with the WorkerPool are cancelled.
execute<T>(Future<T> task(W worker), {PerfCounter? counter}) Future<T>
Registers and schedules a task that returns a single value. Returns a future that completes with the task's value.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
registerWorkerPoolListener(void listener(W worker, bool removed)) Object
Registers a callback to be invoked when a worker thread is added or removed from the pool.
scheduleStream<T>(Stream<T> task(W worker), {PerfCounter? counter}) StreamTask<T>
Registers and schedules a task that returns a stream of values. Returns a StreamTask
scheduleTask<T>(Future<T> task(W worker), {PerfCounter? counter}) ValueTask<T>
Registers and schedules a task that returns a single value. Returns a ValueTask
start() FutureOr<void>
Ensure at least ConcurrencySettings.minWorkers workers are started (defaulting to 1 if ConcurrencySettings.minWorkers is zero).
stop([bool predicate(W worker)?]) int
Stop idle pool workers matching the predicate. If predicate is null or not provided, all workers will be stopped. Stopping a worker does not interrupt or cancel processing. Workers will complete pending tasks before shutting down. In the meantime, they will not receive any new workload. Returns the number of workers that have been stopped.
stream<T>(Stream<T> task(W worker), {PerfCounter? counter}) Stream<T>
Registers and schedules a task that returns a stream of values. Returns a stream containing the task's values.
toString() String
A string representation of this object.
inherited
unregisterWorkerPoolListener({dynamic listener(W worker, bool removed)?, Object? token}) → void
Unregisters a callback.

Operators

operator ==(Object other) bool
The equality operator.
inherited