Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

RuntimeReceiptBus.ts

36 lines1.2 KB

1/**
2 * RuntimeReceiptBus layers.
3 *
4 * `RuntimeReceiptBusLive` is the production default and intentionally does not
5 * retain or broadcast receipts. `RuntimeReceiptBusTest` installs the in-memory
6 * PubSub-backed implementation used by integration tests that need to await
7 * checkpoint-reactor milestones precisely.
8 *
9 * @module RuntimeReceiptBus
10 */
11import { Effect, Layer, PubSub, Stream } from "effect";
12​
13import {
14 RuntimeReceiptBus,
15 type RuntimeReceiptBusShape,
16 type OrchestrationRuntimeReceipt,
17} from "../Services/RuntimeReceiptBus.ts";
18​
19const makeRuntimeReceiptBus = Effect.succeed({
20 publish: () => Effect.void,
21 streamEventsForTest: Stream.empty,
22} satisfies RuntimeReceiptBusShape);
23​
24const makeRuntimeReceiptBusTest = Effect.gen(function* () {
25 const pubSub = yield* PubSub.unbounded<OrchestrationRuntimeReceipt>();
26​
27 return {
28 publish: (receipt) => PubSub.publish(pubSub, receipt).pipe(Effect.asVoid),
29 get streamEventsForTest() {
30 return Stream.fromPubSub(pubSub);
31 },
32 } satisfies RuntimeReceiptBusShape;
33});
34​
35export const RuntimeReceiptBusLive = Layer.effect(RuntimeReceiptBus, makeRuntimeReceiptBus);
36export const RuntimeReceiptBusTest = Layer.effect(RuntimeReceiptBus, makeRuntimeReceiptBusTest);