Worker class
Represents a JavaScript Worker
object.
Allows running scripts in background threads (Web Workers) via Dart-JS interop.
Example usage:
final worker = Worker('worker.js', WorkerOptions(type: 'module'));
worker.postMessage('Hello from Dart!');
- Available extensions
- Annotations
-
- @JS("Worker")
- @staticInterop
Constructors
- Worker.new(String path, WorkerOptions options)
-
Creates a new web worker that executes the script at the given
path
, using the providedoptions
.factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
addEventListener(
String type, JSFunction listener) → void -
Available on Worker, provided by the WorkerExtension extension
Adds an event listener to the worker, such as for'message'
or'error'
. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
postMessage(
JSAny? data) → void -
Available on Worker, provided by the WorkerExtension extension
Sends a message to the worker. -
removeEventListener(
String type, JSFunction listener) → void -
Available on Worker, provided by the WorkerExtension extension
Removes a previously added event listener. -
terminate(
) → void -
Available on Worker, provided by the WorkerExtension extension
Terminates the worker immediately. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited