| 1 | # Forking: Renamed Combinators and New Options |
| 2 | |
| 3 | The `fork*` family of combinators has been renamed in v4 for clarity, and all |
| 4 | variants now accept an options object for controlling fiber startup behavior. |
| 5 | |
| 6 | ## Renamings |
| 7 | |
| 8 | | v3 | v4 | Description | |
| 9 | | ----------------------------- | ------------------- | -------------------------------------------- | |
| 10 | | `Effect.fork` | `Effect.forkChild` | Fork as a child of the current fiber | |
| 11 | | `Effect.forkDaemon` | `Effect.forkDetach` | Fork detached from parent lifecycle | |
| 12 | | `Effect.forkScoped` | `Effect.forkScoped` | Fork tied to the current `Scope` (unchanged) | |
| 13 | | `Effect.forkIn` | `Effect.forkIn` | Fork in a specific `Scope` (unchanged) | |
| 14 | | `Effect.forkAll` | — | Removed | |
| 15 | | `Effect.forkWithErrorHandler` | — | Removed | |
| 16 | |
| 17 | ## `Effect.fork` → `Effect.forkChild` |
| 18 | |
| 19 | **v3** |
| 20 | |
| 21 | ```ts |
| 22 | import { Effect } from "effect" |
| 23 | |
| 24 | const fiber = Effect.fork(myEffect) |
| 25 | ``` |
| 26 | |
| 27 | **v4** |
| 28 | |
| 29 | ```ts |
| 30 | import { Effect } from "effect" |
| 31 | |
| 32 | const fiber = Effect.forkChild(myEffect) |
| 33 | ``` |
| 34 | |
| 35 | ## `Effect.forkDaemon` → `Effect.forkDetach` |
| 36 | |
| 37 | **v3** |
| 38 | |
| 39 | ```ts |
| 40 | import { Effect } from "effect" |
| 41 | |
| 42 | const fiber = Effect.forkDaemon(myEffect) |
| 43 | ``` |
| 44 | |
| 45 | **v4** |
| 46 | |
| 47 | ```ts |
| 48 | import { Effect } from "effect" |
| 49 | |
| 50 | const fiber = Effect.forkDetach(myEffect) |
| 51 | ``` |
| 52 | |
| 53 | ## Fork Options |
| 54 | |
| 55 | In v4, `forkChild`, `forkDetach`, `forkScoped`, and `forkIn` all accept an |
| 56 | optional options object with the following fields: |
| 57 | |
| 58 | ```ts |
| 59 | { |
| 60 | readonly startImmediately?: boolean | undefined |
| 61 | readonly uninterruptible?: boolean | "inherit" | undefined |
| 62 | } |
| 63 | ``` |
| 64 | |
| 65 | - **`startImmediately`** — When `true`, the forked fiber begins executing |
| 66 | immediately rather than being deferred. Defaults to `undefined` (deferred). |
| 67 | - **`uninterruptible`** — Controls whether the forked fiber can be interrupted. |
| 68 | `true` makes it uninterruptible, `"inherit"` inherits the parent's |
| 69 | interruptibility, and `undefined` uses the default behavior. |
| 70 | |
| 71 | **Usage as data-last (curried)** |
| 72 | |
| 73 | ```ts |
| 74 | import { Effect } from "effect" |
| 75 | |
| 76 | const fiber = myEffect.pipe( |
| 77 | Effect.forkChild({ startImmediately: true }) |
| 78 | ) |
| 79 | ``` |
| 80 | |
| 81 | **Usage as data-first** |
| 82 | |
| 83 | ```ts |
| 84 | import { Effect } from "effect" |
| 85 | |
| 86 | const fiber = Effect.forkChild(myEffect, { startImmediately: true }) |
| 87 | ``` |
| 88 | |
| 89 | ## Removed Combinators |
| 90 | |
| 91 | **`Effect.forkAll`** and **`Effect.forkWithErrorHandler`** have been removed in |
| 92 | v4. For `forkAll`, fork effects individually with `forkChild` or use |
| 93 | higher-level concurrency combinators. For error handling on forked fibers, |
| 94 | observe the fiber's result via `Fiber.join` or `Fiber.await`. |