inngest
Version:
Official SDK for Inngest.com. Inngest is the reliability layer for modern applications. Inngest combines durable execution, events, and queues into a zero-infra platform with built-in observability.
1 lines • 2.35 kB
Source Map (JSON)
{"version":3,"file":"StreamFanout.cjs","names":["#writers"],"sources":["../../../../src/components/realtime/subscribe/StreamFanout.ts"],"sourcesContent":["export class StreamFanout<TInput = unknown> {\n #writers = new Set<WritableStreamDefaultWriter<TInput>>();\n\n createStream<TOutput = TInput>(\n transform?: (chunk: TInput) => TOutput,\n ): ReadableStream<TOutput> {\n const { readable, writable } = new TransformStream<TInput, TOutput>({\n transform: (chunk, controller) => {\n controller.enqueue(\n transform ? transform(chunk) : (chunk as unknown as TOutput),\n );\n },\n });\n\n const writer = writable.getWriter();\n this.#writers.add(writer);\n\n // Eagerly remove the writer if the stream is closed\n writer.closed\n .catch(() => {}) // Suppress unhandled promise rejection to avoid noisy logs\n .finally(() => {\n this.#writers.delete(writer);\n });\n\n return readable;\n }\n\n write(chunk: TInput) {\n for (const writer of this.#writers) {\n writer.ready\n .then(() => writer.write(chunk))\n // Dereference the writer if we fail, as this means it's closed\n .catch(() => this.#writers.delete(writer));\n }\n }\n\n close() {\n for (const writer of this.#writers) {\n try {\n void writer.close().catch(() => {\n // Ignore errors, as the writer may already be closed.\n });\n } catch {\n // Ignore errors, as we are closing the stream and the writer may\n // already be closed, especially if the stream is closed before the\n // writer is closed or if the stream is cancelled.\n }\n }\n\n this.#writers.clear();\n }\n\n size() {\n return this.#writers.size;\n }\n}\n"],"mappings":";;AAAA,IAAa,eAAb,MAA4C;CAC1C,2BAAW,IAAI,KAA0C;CAEzD,aACE,WACyB;EACzB,MAAM,EAAE,UAAU,aAAa,IAAI,gBAAiC,EAClE,YAAY,OAAO,eAAe;AAChC,cAAW,QACT,YAAY,UAAU,MAAM,GAAI,MACjC;KAEJ,CAAC;EAEF,MAAM,SAAS,SAAS,WAAW;AACnC,QAAKA,QAAS,IAAI,OAAO;AAGzB,SAAO,OACJ,YAAY,GAAG,CACf,cAAc;AACb,SAAKA,QAAS,OAAO,OAAO;IAC5B;AAEJ,SAAO;;CAGT,MAAM,OAAe;AACnB,OAAK,MAAM,UAAU,MAAKA,QACxB,QAAO,MACJ,WAAW,OAAO,MAAM,MAAM,CAAC,CAE/B,YAAY,MAAKA,QAAS,OAAO,OAAO,CAAC;;CAIhD,QAAQ;AACN,OAAK,MAAM,UAAU,MAAKA,QACxB,KAAI;AACF,GAAK,OAAO,OAAO,CAAC,YAAY,GAE9B;UACI;AAOV,QAAKA,QAAS,OAAO;;CAGvB,OAAO;AACL,SAAO,MAAKA,QAAS"}