@s2-dev/streamstore - v0.26.1
    Preparing search index...

    Class Producer

    Producer provides per-record append semantics on top of a batched AppendSession.

    • submit(record) returns a Promise that resolves once the record has been accepted (written to the batch transform). Backpressure is applied automatically via the transform stream when the AppendSession is at capacity.
    • ticket.ack() returns a Promise that resolves once the record is durable.
    • flush() emits the current partial batch and waits for all records submitted before it to become durable, without closing the Producer.

    See the "Producer API" section of the root README for guidance on sizing batches, wiring transforms, and handling application-level ids.

    const appendSession = await stream.appendSession();
    const producer = new Producer(new BatchTransform(), appendSession);
    const writer = producer.writable.getWriter();
    await writer.write(AppendRecord.string({ body: "hello" }));
    await writer.close();

    for await (const ack of producer.readable) {
    console.log("record durable at seq", ack.seqNum());
    }

    await producer.close();

    Implements

    • AsyncDisposable
    Index

    Constructors

    Properties

    appendSession: AppendSession
    batchTransform: BatchTransform
    pump: Promise<void>
    readable: ReadableStream<IndexedAppendAck>
    transformReader: ReadableStreamDefaultReader<AppendInput>
    transformWriter: WritableStreamDefaultWriter<AppendRecord>
    writable: WritableStream<AppendRecord>

    Methods

    • Close the Producer gracefully.

      Waits for all pending records to be flushed, submitted, and acknowledged. If any error occurred during the Producer's lifetime, this method throws it.

      Returns Promise<void>

    • Force the current partial batch to be emitted and wait for every record submitted before this call to become durable.

      An empty flush does not append a batch. Submissions queued after this call are excluded, and the Producer remains open for further submissions. If a append included in this flush fails, this throws the same terminal error as its record ticket.

      Returns Promise<void>