Class WriteChannel<Write>

Allows writing to a worker.

Example

An example worker script:

// Setup the channel to be "string" (denoted by the type) with data of type string (denoted by data).
type MyMessage = {type: "string", data: string};
const rwChannel = new ReadWriteChannel<MyMessage, MyMessage>();

// writes to the string channel:
rwChannel.write.string("foo");

Type Parameters

Hierarchy

Constructors

Properties

Methods

Constructors

Properties

cancel: {
    reader: ChannelRelease<DataMessage<void>>;
} = ...

Propagate cancel on all readers

Example

const rChannel = new ReadChannel();

// cancels the "string" channel.
rChannel.cancel.reader.string();

Type declaration

close: {
    writer: ChannelRelease<Write>;
} = ...

Propagate close on all writers of channel

Example

const writer = new WriteChannel();

// closes the "string" channel.
writer.close.writer.string();

Type declaration

write: ChannelWrite<Write> = ...

Write to the channel.

Example

An example worker script:

// Setup the channel to be "string" (denoted by the type) with data of type string (denoted by data).
type MyMessage = {type: "string", data: string};
const rwChannel = new ReadWriteChannel<MyMessage, MyMessage>();

// writes to the string channel:
rwChannel.write.string("foo");

Methods

  • Connect the readFrom or writeTo worker/port to either recieve from or send to to a different message port.

    Parameters

    • target: "writeTo" | "readFrom"

      The worker/port to send the connection change to.

    • action: "change-reader" | "change-writer"

      Whether you want to change the "writable" end or the "readable" end of the target

    • connection: MessagePort

      The connection that should now be written to or read from.

    Returns void

  • Ends the communication of the channel. You can always restart the channel with .start().

    Returns void

  • Starts the channel. Called automatically from the constructor, but if you ever .end() the channel this will start it again.

    Returns void

Generated using TypeDoc