Dart API Referencedart:isolateReceivePort

ReceivePort interface

ReceivePorts, together with SendPorts, are the only means of communication between isolates. ReceivePorts have a toSendPort method which returns a SendPort. Any message that is sent through this SendPort is delivered to the ReceivePort it has been created from. There, they are dispatched to the callback that has been registered on the receive port.

A ReceivePort may have many SendPorts.

interface ReceivePort default _ReceivePortFactory {

  /**
   * Opens a long-lived port for receiving messages. The returned port
   * must be explicitly closed through [ReceivePort.close].
   */
  ReceivePort();

  /**
   * Sets up a callback function for receiving pending or future
   * messages on this receive port.
   */
  void receive(void callback(var message, SendPort replyTo));

  /**
   * Closes this receive port immediately. Pending messages will not
   * be processed and it is impossible to re-open the port. Single-shot
   * reply ports, such as those created through [SendPort.call], are
   * automatically closed when the reply has been received. Multiple
   * invocations of [close] are allowed but ignored.
   */
  void close();

  /**
   * Creates a new send port that sends to this receive port. It is legal to
   * create several [SendPort]s from the same [ReceivePort].
   */
  SendPort toSendPort();

}

Constructors

new ReceivePort() #

Opens a long-lived port for receiving messages. The returned port must be explicitly closed through ReceivePort.close.

ReceivePort();

Methods

void close() #

Closes this receive port immediately. Pending messages will not be processed and it is impossible to re-open the port. Single-shot reply ports, such as those created through SendPort.call, are automatically closed when the reply has been received. Multiple invocations of close are allowed but ignored.

void close();

void receive(void callback(message, SendPort replyTo)) #

Sets up a callback function for receiving pending or future messages on this receive port.

void receive(void callback(var message, SendPort replyTo));

SendPort toSendPort() #

Creates a new send port that sends to this receive port. It is legal to create several SendPorts from the same ReceivePort.

SendPort toSendPort();