Propagate cancel on all readers
const rChannel = new ReadChannel();
// cancels the "string" channel.
rChannel.cancel.reader.string();
Propagate close on all writers of channel
const writer = new WriteChannel();
// closes the "string" channel.
writer.close.writer.string();
Readonly
readRead from the channel
// 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>();
// Read data of type string from the "string" channel.
const str = await rwChannel.read.string();
Readonly
readRead from the channel
// 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>();
for await (const item of rwChannel.readAll.string()) {
console.log(item);
}
Readonly
writeWrite to the channel.
// 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");
Connect the readFrom or writeTo worker/port to either recieve from or send to to a different message port.
The worker/port to send the connection
change to.
Whether you want to change the "writable" end or the "readable" end of the target
The connection that should now be written to or read from.
Generated using TypeDoc
ReadWriteChannel is a readable and writable Channel.
Example
An example worker script: