1/**
2 * @title Running effects with NodeRuntime and BunRuntime
3 *
4 * Use `NodeRuntime.runMain` to run an Effect program as your process entrypoint.
5 */
6import { BunRuntime } from "@effect/platform-bun"
7import { NodeRuntime } from "@effect/platform-node"
8import { Effect, Layer } from "effect"
9
10const Worker = Layer.effectDiscard(Effect.gen(function*() {
11 yield* Effect.logInfo("Starting worker...")
12 yield* Effect.forkScoped(Effect.gen(function*() {
13 while (true) {
14 yield* Effect.logInfo("Working...")
15 yield* Effect.sleep("1 second")
16 }
17 }))
18}))
19
20const program = Layer.launch(Worker)
21
22// `runMain` installs SIGINT / SIGTERM handlers and interrupts running fibers
23// for graceful shutdown.
24NodeRuntime.runMain(program, {
25 // Disable automatic error reporting if your app already centralizes it.
26 disableErrorReporting: true
27})
28
29// Bun has the same API shape:
30BunRuntime.runMain(program, { disableErrorReporting: true })