IsolateBus class

Sends messages between the isolates of one Dox app.

Each isolate has its own memory. To tell the other isolates about something (a broadcast for their sockets, a cache key to forget), an isolate publishes a message on a channel. Every other isolate that listens on that channel gets it. A listener never sees the messages of another channel.

IsolateBus.instance.on('users').listen(onMessage);
IsolateBus.instance.publish('users', <Object>['changed', 42]);

The main isolate keeps a hub. DoxIsolate gives every isolate it starts the port of the hub, and the isolate calls connect with it. With one isolate, nothing is sent: there is no other isolate.

A message must be something a SendPort can send: null, bool, num, String, typed data, and lists and maps of those.

Properties

hashCode → int
The hash code for this object.
no setterinherited
port → SendPort
The port of the hub. Opened on the first call, in the main isolate.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
size → int
Number of isolates that listen on the bus, this one included. It is 1 until this isolate calls on and the hub answers.
no setter

Methods

close() → void
Leave the bus and close the ports. In the main isolate it also closes the hub.
connect(SendPort? hub, int id) → void
Use the hub hub (a port of the main isolate) from now on. id is the id of this isolate. null hub: this is the main isolate.
drop(int id) → void
In the main isolate: forget isolate id, because it stopped. DoxIsolate calls it when an isolate exits, also after a crash.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
on(String channel) → Stream<Object?>
Messages on channel from the other isolates. The first call (on any channel) joins the bus. An isolate never gets its own messages.
publish(String channel, Object? message) → void
Sends message to every other isolate that listens on channel.
toString() → String
A string representation of this object.
inherited

Operators

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

Static Properties

instance → IsolateBus
one per isolate
final