WorkerPool<W extends Worker> class abstract

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.new(WorkerFactory<W> _workerFactory, {ConcurrencySettings? concurrencySettings, ExceptionManager? exceptionManager})
Create a worker pool.

Properties

channelLogger ↔ Logger?
getter/setter pairoverride
concurrencySettings ConcurrencySettings
Concurrency settings.
final
exceptionManager ExceptionManager
no setteroverride
fullStats Iterable<WorkerStat>
Full worker statistics.
no setter
hashCode int
The hash code for this object.
no setterinherited
isReleased bool
Returns true if the instance has been released, false otherwise.
no setterinherited
maxSize int
Maximum number of workers.
no setter
operations OperationsMap
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

Methods

autoRelease(List<Releasable?> instances) → void
The autoRelease method is used to register a set of Releasable instances that will be automatically released when this instance becomes unreachable. Please note that this mechanism is based on Dart's Finalizer feature which makes no guarantee that it will ever be called. Depending on instance dependencies and their relationship with the internal Finalizer instance, it may even never be called. For instance, make sure this is never passed to autoRelease as this will create a cyclic graph of dependencies that will prevent finalization to happen.
inherited
cancel(Task task, [String? message]) → void
Task cancelation. If a specific task is provided, only this task will be canceled. Otherwise, all tasks registered with the WorkerPool are canceled.
cancelAll([String? message]) → void
Task cancelation. If a specific task is provided, only this task will be canceled. Otherwise, all tasks registered with the WorkerPool are canceled.
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(WorkerStat, bool)) Object
Registers a callback to be invoked when a worker thread is added or removed from the pool.
release() → void
The release method must be overriden in derived classes to clean up any resources they use. Implementations should not throw and must call super.release() in a finally block. If a derived class defines Releasable fields, these fields should be released of in this method. Note for implementers: it should be safe to call this method several times.
scheduleStreamTask<T>(Stream<T> task(W worker), {PerfCounter? counter}) StreamTask<T>
Registers and schedules a task that returns a stream of values. Returns a StreamTask.
scheduleValueTask<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).
override
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.
override
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.
terminate([TaskTerminatedException? ex]) → void
override
toString() String
A string representation of this object.
inherited
track() → dynamic
Implementations should call this method e.g. at construction time to make sure they will be trackable in debugging scenarios. See ReleasableTracker.enable for more information.
inherited
unregisterWorkerPoolListener({dynamic listener(WorkerStat, bool)?, Object? token}) → void
Unregisters a callback.

Operators

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