LocalWorker<W extends WorkerService> class abstract

Base local worker class.

Local workers are similar to other Workers except that they run in the context of the current thread. They do not create any platform thread (such as Isolate or Web Worker) but they provide a channel that can be shared with other workers to support communication between threads. One interesting use-case is accessing UI components or platform plugins in Flutter, where only code running in the main thread is allowed access to such features. Creating a LocalWorker in the main application and sharing its channel with other workers enables providing access to Flutter features.

Local workers wrap around a WorkerService. Messages sent to the local worker are deserialized as WorkerRequest and dispatched to a handler defined in the service's WorkerService.operations map according to the WorkerRequest.command.

Implemented types

Constructors

LocalWorker(W service)
LocalWorker.create(W service)
factory

Properties

channel Channel?
The local worker's Channel.
no setter
hashCode int
The hash code for this object.
no setterinherited
operations Map<int, CommandHandler>
Local Workers do not need an operations map.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
service → W
The WorkerService associated to this local worker.
final
sharedChannel Channel?
A Channel to communicate with this local worker. This channel should be provided to clients so they can invoke services from the local worker.
no setter

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
stop() → void
Stops the local worker.
toString() String
A string representation of this object.
inherited

Operators

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