Skip to content

Commit c15bf90

Browse files
committed
docs: add acquireRelease example for non-Bus resources
1 parent 822e292 commit c15bf90

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

packages/opencode/specs/effect-migration.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,15 @@ const cache = yield* InstanceState.make<State>(
100100
)
101101
```
102102

103+
- **Resource cleanup**: Use `Effect.acquireRelease` or `Effect.addFinalizer` for resources that need teardown (native watchers, process handles, etc.):
104+
105+
```ts
106+
yield* Effect.acquireRelease(
107+
Effect.sync(() => nativeAddon.watch(dir)),
108+
(watcher) => Effect.sync(() => watcher.close()),
109+
)
110+
```
111+
103112
- **Background fibers**: Use `Effect.forkScoped` — the fiber is interrupted on disposal.
104113
- **Side effects at init**: Config notification, event wiring, etc. all belong in the init closure. Callers just do `InstanceState.get(cache)` to trigger everything, and `ScopedCache` deduplicates automatically.
105114

0 commit comments

Comments
 (0)