remote-web-streams
Version:
Web streams that work across web workers and iframes.
32 lines (26 loc) • 1.18 kB
TypeScript
/**
* Returns which parts of a chunk should be transferred to the remote end.
*
* @param chunk The chunk to be sent
* @return An array of {@link Transferable transferable} chunk parts
*/
type TransferChunkCallback<T> = (chunk: T) => Transferable[];
interface MessagePortSinkOptions<W = any> {
transferChunk?: TransferChunkCallback<W>;
}
declare function fromWritablePort<W = any>(port: MessagePort, options?: MessagePortSinkOptions<W>): WritableStream<W>;
declare class RemoteReadableStream<R = any> {
readonly writablePort: MessagePort;
readonly readable: ReadableStream<R>;
constructor();
}
interface RemoteWritableStreamOptions$1<W = any> extends MessagePortSinkOptions<W> {
}
declare class RemoteWritableStream<W = any> {
readonly readablePort: MessagePort;
readonly writable: WritableStream<W>;
constructor(options?: RemoteWritableStreamOptions$1<W>);
}
declare function fromReadablePort<R = any>(port: MessagePort): ReadableStream<R>;
type RemoteWritableStreamOptions<W = any> = RemoteWritableStreamOptions$1<W>;
export { RemoteReadableStream, RemoteWritableStream, RemoteWritableStreamOptions, fromReadablePort, fromWritablePort };