send method

void send(
  1. dynamic message, {
  2. required dynamic to,
})

Send message to a spawned isolate.

message must have a type corresponding to the type passed to spawn if dynamic was not used. May not be null.

to must be either a String containing the name of an existing isolate or a HandledIsolate returned by the spawn function. May not be null.

Throws if to or message are null.

Implementation

void send(dynamic message, {required dynamic to}) {
  assert(to != null);
  assert(message != null);

  if (to is String) {
    assert(isolates.containsKey(to));
    isolates[to]!.messenger.send(message);
  } else if (to is HandledIsolate) {
    to.messenger.send(message);
  } else {
    throw TypeError();
  }
}