docs: add acquireRelease example for non-Bus resources

This commit is contained in:
Kit Langton
2026-03-22 13:08:58 -04:00
parent 822e2922a3
commit c15bf90847
@@ -100,6 +100,15 @@ const cache = yield* InstanceState.make<State>(
)
```
- **Resource cleanup**: Use `Effect.acquireRelease` or `Effect.addFinalizer` for resources that need teardown (native watchers, process handles, etc.):
```ts
yield* Effect.acquireRelease(
Effect.sync(() => nativeAddon.watch(dir)),
(watcher) => Effect.sync(() => watcher.close()),
)
```
- **Background fibers**: Use `Effect.forkScoped` — the fiber is interrupted on disposal.
- **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.