| 1 | /** |
| 2 | * Bun process runner for Effect programs. |
| 3 | * |
| 4 | * This module exports `runMain`, which runs one Effect as the main process |
| 5 | * fiber in Bun. It reuses the shared Node runtime runner, including its error |
| 6 | * reporting, signal handling, and optional teardown behavior. |
| 7 | * |
| 8 | * @since 4.0.0 |
| 9 | */ |
| 10 | import * as NodeRuntime from "@effect/platform-node-shared/NodeRuntime" |
| 11 | import type { Effect } from "effect/Effect" |
| 12 | import type { Teardown } from "effect/Runtime" |
| 13 | |
| 14 | /** |
| 15 | * Helps you run a main effect with built-in error handling, logging, and signal management. |
| 16 | * |
| 17 | * **When to use** |
| 18 | * |
| 19 | * Use to run a Bun application's main Effect with structured error handling, |
| 20 | * log management, interrupt support, or advanced teardown capabilities. |
| 21 | * |
| 22 | * **Details** |
| 23 | * |
| 24 | * This function launches an Effect as the main entry point, setting exit codes |
| 25 | * based on success or failure, handling interrupts (e.g., Ctrl+C), and optionally |
| 26 | * logging errors. By default, it logs errors and uses a "pretty" format, but both |
| 27 | * behaviors can be turned off. You can also provide custom teardown logic to |
| 28 | * finalize resources or produce different exit codes. |
| 29 | * |
| 30 | * An optional object that can include: |
| 31 | * - `disableErrorReporting`: Turn off automatic error logging. |
| 32 | * - `disablePrettyLogger`: Avoid adding the pretty logger. |
| 33 | * - `teardown`: Provide custom finalization logic. |
| 34 | * |
| 35 | * @category running |
| 36 | * @since 4.0.0 |
| 37 | */ |
| 38 | export const runMain: { |
| 39 | ( |
| 40 | options?: { |
| 41 | readonly disableErrorReporting?: boolean | undefined |
| 42 | readonly teardown?: Teardown | undefined |
| 43 | } |
| 44 | ): <E, A>(effect: Effect<A, E>) => void |
| 45 | <E, A>( |
| 46 | effect: Effect<A, E>, |
| 47 | options?: { |
| 48 | readonly disableErrorReporting?: boolean | undefined |
| 49 | readonly teardown?: Teardown | undefined |
| 50 | } |
| 51 | ): void |
| 52 | } = NodeRuntime.runMain |