squadron_worker library

Classes

BaseDevSquadronLogger
Base class for dev loggers.
BaseSquadronLogger
Base class for simple loggers
CancellationToken
Base cancellation token.
Channel
A Channel supports communication from a client to a platform worker. It is used to send a WorkerRequest to a platform worker.
CompositeToken
Composite cancellation token. The token is cancelled automatically depending on mode: with CompositeMode.any, the composite token is cancelled as soon as when one of the tokens is cancelled. With CompositeMode.any, the composite token is cancelled when all tokens are cancelled.
ConcurrencySettings
Concurrency settings governing parallelization of workers in a WorkerPool.
ConsoleSquadronLogger
Simple console logger (print function)
DevSquadronLogger
Simple logger based on dart:dev log function
GenericMarshaler<T>
Base class to abstract S in SquadronMarshaler<T, S>.
GenericMarshaller<T>
Provided temporarily for compatibility reasons. See GenericMarshaler.
IdentityMarshaler<T>
Identity marshaler.
IdentityMarshaller<T>
Provided temporarily for compatibility reasons. See IdentityMarshaler.
LocalWorker<W extends WorkerService>
Base local worker class.
LocalWorkerClient
Base class used to communicate with a LocalWorker.
ParentSquadronLogger
Logger for workers, forwarding log messages to parent
PerfCounter
Simple performance counter to consolidate statistics about woker tast execution: total number of calls, total number of errors, total elapsed time, and max elapsed time.
PerfCounterSnapshot
A snapshot of a PerfCounter's values.
ServiceInstaller
Extend this class or implement this interface in your worker service if it needs to take action when the worker thread is started or stopped.
Squadron
Squadron singleton. The main application thread and each worker thread will have their own private Squadron singleton.
SquadronLogger
Basic interface for logging
SquadronLogLevel
Log level constants, compatible with package:logging
SquadronMarshaler<T, S>
Base class to serialize/deserialize data of type T to a transferable type S.
SquadronMarshaller<T, S>
Provided temporarily for compatibility reasons. See SquadronMarshaler.
StreamTask<T>
Class representing a Task returning a stream of values.
Task<T>
Base worker task class
TimeOutToken
Time-out cancellation tokens used by callers of worker services. The token is cancelled automatically after a period of time indicated by duration with a countdown starting only when the task is assigned to a platform worker.
ValueTask<T>
Class representing a Task returning a single value.
Worker
Base worker class.
WorkerChannel
A WorkerChannel supports communication from a platform worker to the client that posted the WorkerRequest. It is used to send WorkerResponse back to the client.
WorkerPool<W extends Worker>
Worker pool responsible for instantiating, starting and stopping workers running in parallel. A WorkerPool is also responsible for creating and assigning WorkerTasks to Workers.
WorkerService
Base class for a worker service.
WorkerStat
Base statistics for worker.

Enums

CompositeMode
Composite token cancellation mode

Extensions

WorkerMessageImpl on List
WorkerRequestImpl on WorkerRequest
Extension methods operating on a List as a WorkerRequest. WorkerRequests are used to communicate from a Channel to a Worker. Typically a WorkerRequest consists of a command ID and a list of arguments. The command ID is used by the Worker to dispatch the WorkerRequest to the method responsible for handling it. The command's arguments are passed as a list and should only contain primitive values or objects that can be transfered across workers. For applications running on a VM platform, Dart objects should be safe according to Dart's documentation of SendPort.send. WorkerRequestImpl also implements specific requests used for worker startup, stream/token cancellation, worker termination...
WorkerResponseImpl on WorkerResponse
Class used to communicate from a Worker to clients. WorkerResponses are used to provide individual results to the client. Future-based services simply return a single WorkerResponse with the result. Streaming services will return one WorkerResponses for each stream item and mmust send a WorkerResponseImpl.closeStream message to indicate completion. WorkerResponses can also send error messages. Extension methods operating on a List as a WorkerResponse. WorkerResponse is used to provide individual results to the client. Future-based services simply return a single WorkerResponse with the result. Stream services return one WorkerResponse for each stream item and mmust send a WorkerResponseImpl.closeStream message to indicate completion. A WorkerResponse can also be used to send error messages.

Functions

run(WorkerInitializer initializer, [List? command, SquadronLogger? logger]) → void
Instantiates a WorkerService via the initializer and installs the service in a platform worker. The command argument is ignored on Web platforms. On native platforms, the command argument must be set to the Isolate's startup parameter.

Typedefs

CommandHandler = FutureOr Function(WorkerRequest req)
EntryPoint = dynamic
PlatformWorker = dynamic
PlatformWorkerHook = PlatformWorkerHook
PostRequest = void Function(WorkerRequest req)
SquadronCallback = void Function()
WorkerExceptionDeserializer = WorkerException? Function(List data)
WorkerFactory<W> = W Function()
WorkerInitializer = FutureOr<WorkerService> Function(WorkerRequest startRequest)
WorkerMessage = List
Make WorkerMessage a List to minimize serialization overhead.
WorkerRequest = WorkerMessage
Make WorkerRequest a WorkerMessage to minimize serialization overhead.
WorkerResponse = WorkerMessage
Make WorkerResponse a WorkerMessage to minimize serialization overhead.

Exceptions / Errors

CancelledException
Exception to keep track of task cancellation.
SquadronError
Squadron Error
SquadronException
Base abstract class for exceptions in Squadron.
TaskTimeoutException
Exception to keep track of task timeouts.
WorkerException
Exception to keep track of errors encountered in a worker.