IsolateParent<S, R> class
abstract
A parent isolate that can spawn children isolates.
This class runs some initialization logic in init, which may spawn some children isolates using spawn. Each child isolate should be a subclass of IsolateChild, and must override its ID to be unique from every other child that this parent will spawn. It is an error for two IsolateChilds spawned by spawn to have the same ID, as it will confuse the parent.
Two-way communication is implemented by calling send to send some data to the child with the given ID, and by overriding onData to be notified when a child sends some data back. Be sure to call dispose when finished with this parent to stop listening to messages.
This class has two type arguments, S
for the type being sent and R
for the type being
received. To keep the logic straightforward, this parent must send the same type S
to all
its children, and each child can only send messages of type R
. If different data types
are desired, try making a more complex class to contain the fields you need, or make a new
parent to spawn children of different types.
Note that S
and R
will be flipped with respect to this class's children: if you send
integers and expect strings, then each child must expect integers and send strings.
Constructors
- IsolateParent()
-
Starts listening to
IsolatePayload
s sent by this isolate's children.
Properties
Methods
-
dispose(
[int priority = Isolate.beforeNextEvent]) → Future< void> - Kills all isolates and clears all handlers.
-
init(
) → void - Starts running this isolate's "main" code. Usually used to spawn children.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onData(
R data, Object id) → void - A callback that runs when data is sent by a child.
-
send(
{required S data, required Object id}) → void - Sends the object to the child with the given ID.
-
spawn(
IsolateChild< R, S> child) → Future<Isolate> - Spawns the child and calls IsolateChild.init to establish two-way communication.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited