LocalWorker<W> class abstract interface

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 WorkerRequests and dispatched to a handler defined in the _service's WorkerService.operations map according to the WorkerRequest.command.

Implemented types

Constructors

LocalWorker.create(W service, [OperationsMap? operations, ExceptionManager? exceptionManager])
factory

Properties

channel Channel?
The local worker's Channel.
no setter
channelLogger ↔ Logger?
getter/setter pairinherited
exceptionManager ExceptionManager
no setteroverride
hashCode int
The hash code for this object.
no setterinherited
isReleased bool
Returns true if the instance has been released, false otherwise.
no setterinherited
operations OperationsMap
Forward to underlying service.
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
service → W
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
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
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.
inherited
start() Future<void>
Starts the local worker.
override
stop() → void
Stops the local worker.
override
terminate([TaskTerminatedException? ex]) → void
Terminates the local worker.
override
toString() String
A string representation of this object.
inherited
track() → void
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

Operators

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