@ThreadSafe
class MessagePort : AutoCloseable


Represents a single message port in a message channel.

A message port is created as part of a message channel, which consists of two entangled message ports. When one port sends a message, it is received by the other port, and vice versa. These ports can exist in separate processes. For example, a port in a Java-based Android application can send and receive messages to and from a port in a JavaScript isolate.

A message channel between the app and an isolate can be established using createMessageChannel, which returns the app-side MessagePort.

A reference to the MessagePort is maintained so long as the message channel remains alive.

This class is thread-safe. Messages can be posted from any thread.

Summary

Public functions

Unit

Closes the message port to free resources.

Unit
postMessage(message: Message)

Posts a message over the channel to the other port.

Public functions

close

Added in 1.1.0-alpha02
fun close(): Unit

Closes the message port to free resources.

Once the port is closed, sent and received messages are silently discarded.

postMessage

Added in 1.1.0-alpha02
fun postMessage(message: Message): Unit

Posts a message over the channel to the other port.

This method does not block on the message being processed on the receiving side and can be called from any thread.

Messages sent via a closed or dead port/channel are silently discarded.

Parameters
message: Message

The Message to send.