The best way to control Claude Code, Codex and more from any computer or phone

main
ts 30 lines 941 Bytes
Raw
1 /**
2 * @title Running effects with NodeRuntime and BunRuntime
3 *
4 * Use `NodeRuntime.runMain` to run an Effect program as your process entrypoint.
5 */
6 import { BunRuntime } from "@effect/platform-bun"
7 import { NodeRuntime } from "@effect/platform-node"
8 import { Effect, Layer } from "effect"
9
10 const 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
20 const program = Layer.launch(Worker)
21
22 // `runMain` installs SIGINT / SIGTERM handlers and interrupts running fibers
23 // for graceful shutdown.
24 NodeRuntime.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:
30 BunRuntime.runMain(program, { disableErrorReporting: true })