Interface WxEnd

Source
Expand description

Messaging primitive representing one end of an established messaging channel

This is an abstraction of the underlying messaging channel, be it a Worker, Window, or possibly WebSocket or HTTP requests in the future.

Workex provides factory functions for creating WxEnds for different messaging channels. Note that since WxEnd is an abstraction over an established channel, the design pattern is that any valid WxEnd objects you create with functions in this library will first establish the handshake.

interface WxEnd {
    close: () => void;
    isClosed: () => boolean;
    onClose: (callback: () => void) => () => void;
    send: (message: WxMessage) => WxVoid;
}

Properties§

§close: { ... }

Mark the channel as closed and unregisters all message handlers registered by the end. If handshake is still in progress, it will be aborted.

§isClosed: { ... }

Check if the end is closed

§onClose: { ... }

Add a subscriber to the close event. The subscriber will be called when the end is closed at most once

§send: { ... }

Send a message to the other end