[codex] Add scoped resource helpers#64
Conversation
Expose ergonomic wrappers for Effect scoped resources through fx.acquireRelease and fx.scoped, plus fx.layerScoped for scoped dependency layers. Add runtime coverage for success, failure, interruption, and app disposal finalization, along with type-level assertions for success, failure, and dependency inference. Update resource and API docs, and include the required changeset for the public API addition.
Dispose the reusable fx.app in the dependencies example after the exported main promise settles. CI timed out while running the example smoke test because the child Bun process could stay alive until the 5s test timeout on the runner.
Greptile SummaryThis PR exposes three scoped-resource helpers —
Confidence Score: 5/5Safe to merge — all new helpers are direct aliases over well-tested Effect primitives with no custom logic, and the added tests cover every documented failure mode. The implementation is three one-liner aliases, the tests exercise success, failure, interruption, and disposal, and the type-level assertions confirm the No files require special attention.
|
| Filename | Overview |
|---|---|
| src/builders.ts | Adds acquireRelease and scoped as thin pass-throughs to Effect.acquireRelease and Effect.scoped; no logic added. |
| src/dependencies.ts | Adds layerScoped as a direct alias for Layer.scoped; consistent with existing layerSync/layer patterns. |
| src/index.ts | Exports the three new helpers in the fx object; placement is consistent with existing layout. |
| test/runtime.test.ts | Adds four runtime tests covering success, typed failure, fiber interruption, and layerScoped disposal; all paths are exercised. |
| test/types.test.ts | Adds compile-time assertions confirming Scope.Scope appears in deps of a bare acquireRelease task and is eliminated after fx.scoped / fx.layerScoped. |
| examples/dependencies.ts | Updates the example to call app.dispose() in a .finally() handler, demonstrating proper cleanup practice for apps that use scoped layers. |
| docs/resources.md | Adds a "Scoped Resources" section with concrete usage examples for acquireRelease, scoped, and layerScoped; updates the native escape-hatch guidance. |
| docs/api-reference.md | Adds table rows for fx.acquireRelease, fx.scoped, and fx.layerScoped in the correct sections. |
| .changeset/scoped-resource-helpers.md | Minor changeset correctly classifying the new public API additions. |
Reviews (1): Last reviewed commit: "test: dispose dependency smoke app" | Re-trigger Greptile
Summary
Closes #53.
This adds focused scoped resource helpers to the public
fxAPI:fx.acquireReleasefor acquiring a scoped resource and registering its finalizerfx.scopedfor opening and closing a scope around a taskfx.layerScopedfor scoped dependency layers that release resources when the runtime boundary is disposedWhy
fluent-effectalready exposedfx.acquireUseRelease/fx.bracket, but scoped-resource workflows still required importing native Effect helpers fromfluent-effect/effect. Resource safety is central enough to warrant a small ergonomic surface without wrapping the full Effect resource API.Validation
bun fmtbun lint:fixbun testbun typecheckNotes
The docs now clarify when to use direct acquire/use/release versus scoped resources and when to fall back to native Effect APIs for advanced finalizer composition.