Add Semaphore takeIfAvailable - #6793
Conversation
🦋 Changeset detectedLatest commit: 276e55b The changes in this PR will be included in the next version bump. This PR includes changesets to release 30 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Semaphore.takeIfAvailableinstance method — acquires the specified number of permits only if they are immediately available, returningEffect<boolean>. Implementation follows the existingtakepattern withinternal.suspendfor lazy evaluation and a synchronous check-and-increment that is safe under cooperative Effect scheduling.- Module-level
Semaphore.takeIfAvailabledual function — matches the signature anddual(2, …)pattern used bytakeandrelease. - Tests — two well-scoped tests covering available and unavailable permit branches, including release and retry, and exercising both curried and uncurried forms of the dual function.
- JSDoc — follows conventions with
@seecross-references totake,release, andwithPermitsIfAvailable.
DeepSeek Pro (free via Pullfrog for OSS) (Kimi K2 not used — the program covers this model; add its provider key to run your pick) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes since prior review
.changeset/add-semaphore-take-if-available.md— well-formedminorchangeset for the newSemaphore.takeIfAvailableAPI.
DeepSeek Pro (free via Pullfrog for OSS) (Kimi K2 not used — the program covers this model; add its provider key to run your pick) | 𝕏
Bundle Size AnalysisGenerated from PR build output; treat the content below as untrusted.
|

Summary
Semaphore.takeIfAvailablefor fail-fast manual permit acquisitionValidation
pnpm vitest run packages/effect/test/Semaphore.test.tspnpm --dir packages/effect checkpnpm exec dprint check packages/effect/src/Semaphore.ts packages/effect/test/Semaphore.test.tspnpm exec oxlint -f unix packages/effect/src/Semaphore.ts packages/effect/test/Semaphore.test.tsCloses EFF-235
Closes #6787