Skip to content

[codex] Add acquire-use-release helper#45

Merged
samlaycock merged 2 commits into
mainfrom
issue-33-acquire-use-release
May 12, 2026
Merged

[codex] Add acquire-use-release helper#45
samlaycock merged 2 commits into
mainfrom
issue-33-acquire-use-release

Conversation

@samlaycock

Copy link
Copy Markdown
Owner

Summary

Adds a first-class resource safety helper to the root fx API for Issue #33.

Changes

  • Exposes fx.acquireUseRelease as a typed wrapper around Effect's acquire/use/release primitive.
  • Adds fx.bracket as a shorter alias for the same workflow.
  • Adds runtime coverage proving release runs after successful use, failed use, and interruption.
  • Adds type coverage for acquire/use failure inference and release dependency inference.
  • Documents resource-safe workflows in a new Resource Safety guide and links it from the docs index and API reference.
  • Adds a changeset for the new public API.

Impact

Users can now model file handles, connections, locks, spans, and similar resources without dropping to fluent-effect/effect for the common acquire/use/release case. The helper preserves native Effect finalizer semantics: release receives the resource and exit value, runs on success/failure/interruption, and does not contribute a typed failure channel.

Closes #33.

Validation

  • bun test
  • bun typecheck
  • bun fmt --check
  • bun lint
  • bun run build

Expose fx.acquireUseRelease with a fx.bracket alias for resource-safe workflows.

Add runtime coverage for success, failure, and interruption finalization plus type coverage for acquire/use/release inference.

Document resource safety guidance and add a changeset for the new public API.
@samlaycock samlaycock marked this pull request as ready for review May 12, 2026 20:10
@greptile-apps

greptile-apps Bot commented May 12, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds fx.acquireUseRelease and its alias fx.bracket as thin wrappers around Effect's native acquireUseRelease primitive, giving users a first-class resource-safety API without leaving the fluent-effect surface.

  • src/builders.ts / src/index.ts: both names are direct re-exports of Effect.acquireUseRelease, consistent with the pattern used for other builders (fx.sync, fx.fail, etc.).
  • test/runtime.test.ts: three new tests cover the success, typed-failure, and fiber-interruption paths; the interruption test uses a Deferred + 1-second timeoutFail guard to avoid a flaky pass.
  • test/types.test.ts: compile-time assertions confirm that the result type, error union (acquire ∪ use only — release never leaks E), and dependency channel (release deps propagate) are all inferred correctly.
  • docs/resources.md: new guide with a worked connection example; the release handler uses fx.sync with an inner try/catch, keeping the error channel clean in line with the documented finalizer convention.

Confidence Score: 5/5

Safe to merge — the change is a thin re-export with comprehensive runtime and type-level test coverage.

The implementation delegates entirely to Effect's battle-tested acquireUseRelease, introduces no custom logic that could diverge from Effect's finalizer semantics, and is covered by tests for all three exit paths (success, failure, interruption) as well as compile-time type assertions for result, error, and dependency inference.

No files require special attention.

Important Files Changed

Filename Overview
src/builders.ts Adds acquireUseRelease and bracket as direct re-exports of Effect.acquireUseRelease, consistent with the pattern used for other thin wrappers in this file.
src/index.ts Exposes acquireUseRelease and bracket on the fx object; placement and style are consistent with existing entries.
docs/resources.md New Resource Safety guide with a worked example; release handler correctly uses fx.sync with an inner try/catch so the error channel stays clean.
test/runtime.test.ts Adds runtime tests for success, failure, and interruption paths; the interruption test uses a Deferred + timeout guard to avoid a flaky pass.
test/types.test.ts Type-level tests verify result, error (acquire union use only, release never leaks), and dependency inference for both acquireUseRelease and bracket.
docs/api-reference.md Adds two rows to the builder table for the new methods; accurate and consistent with existing entries.
docs/README.md Inserts a link to the new Resource Safety guide in the docs index at the correct alphabetical position.
.changeset/brave-owls-bracket.md Minor-version changeset correctly describes both new public exports.

Reviews (2): Last reviewed commit: "docs: keep release example error-free" | Re-trigger Greptile

Comment thread docs/resources.md
Update the resource safety guide so the release callback handles cleanup failures inside fx.sync instead of returning a typed failure from fx.try.

This keeps the example aligned with the guidance that acquire-use-release finalizers should not widen the typed error channel.
@samlaycock samlaycock merged commit 15c9ee8 into main May 12, 2026
2 checks passed
@samlaycock samlaycock deleted the issue-33-acquire-use-release branch May 12, 2026 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

P2: Add a first-class bracket/acquire-use-release helper

1 participant