@adviser/cement - v0.0.0
    Preparing search index...

    Class FanoutWriteStream

    WritableStreamDefaultWriter that multiplexes writes to multiple underlying writers.

    FanoutWriteStream broadcasts all write operations to an array of writers simultaneously. All operations (write, close, abort, releaseLock) are applied to all underlying writers. Useful for scenarios like logging to multiple destinations, streaming to multiple consumers, or maintaining redundant copies of stream data.

    // Write to both file and console simultaneously
    const fileStream = new WritableStream({ ... });
    const consoleStream = new ConsoleWriterStream();

    const fanout = new FanoutWriteStream([
    fileStream.getWriter(),
    consoleStream.getWriter()
    ]);

    // This writes to both destinations
    await fanout.write(new TextEncoder().encode('Log message'));

    // Close all writers
    await fanout.close();
    // Mirror stream data to multiple endpoints
    const backupWriter = backupStream.getWriter();
    const primaryWriter = primaryStream.getWriter();
    const metricsWriter = metricsStream.getWriter();

    const fanout = new FanoutWriteStream([
    primaryWriter,
    backupWriter,
    metricsWriter
    ]);

    // All three streams receive the data
    for (const chunk of dataChunks) {
    await fanout.write(chunk);
    }

    Implements

    • WritableStreamDefaultWriter<Uint8Array>
    Index

    Constructors

    Properties

    _writers: WritableStreamDefaultWriter<Uint8Array<ArrayBufferLike>>[]
    ready: Promise<never>

    The ready read-only property of the that resolves when the desired size of the stream's internal queue transitions from non-positive to positive, signaling that it is no longer applying backpressure.

    MDN Reference

    closed: Promise<never>

    The closed read-only property of the the stream errors or the writer's lock is released.

    MDN Reference

    desiredSize: number | null = null

    The desiredSize read-only property of the to fill the stream's internal queue.

    MDN Reference

    Methods

    • The abort() method of the the producer can no longer successfully write to the stream and it is to be immediately moved to an error state, with any queued writes discarded.

      MDN Reference

      Parameters

      • Optionalreason: unknown

      Returns Promise<void>

    • The write() method of the operation.

      MDN Reference

      Parameters

      • Optionalchunk: Uint8Array<ArrayBufferLike>

      Returns Promise<void>