Skip to content

Add Semaphore takeIfAvailable - #6793

Merged
tim-smart merged 2 commits into
mainfrom
agent/codex-engineer/81b3d1db
Jul 30, 2026
Merged

Add Semaphore takeIfAvailable#6793
tim-smart merged 2 commits into
mainfrom
agent/codex-engineer/81b3d1db

Conversation

@tim-smart

Copy link
Copy Markdown
Contributor

Summary

  • add Semaphore.takeIfAvailable for fail-fast manual permit acquisition
  • expose instance and dual module-level signatures
  • test available and unavailable permit branches, including explicit release ownership

Validation

  • pnpm vitest run packages/effect/test/Semaphore.test.ts
  • pnpm --dir packages/effect check
  • pnpm exec dprint check packages/effect/src/Semaphore.ts packages/effect/test/Semaphore.test.ts
  • pnpm exec oxlint -f unix packages/effect/src/Semaphore.ts packages/effect/test/Semaphore.test.ts

Closes EFF-235
Closes #6787

@github-project-automation github-project-automation Bot moved this to Discussion Ongoing in PR Backlog Jul 30, 2026
@changeset-bot

changeset-bot Bot commented Jul 30, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 276e55b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 30 packages
Name Type
effect Major
@effect/opentelemetry Major
@effect/platform-browser Major
@effect/platform-bun Major
@effect/platform-deno Major
@effect/platform-node-shared Major
@effect/platform-node Major
@effect/vitest Major
@effect/ai-anthropic Major
@effect/ai-openai-compat Major
@effect/ai-openai Major
@effect/ai-openrouter Major
@effect/atom-react Major
@effect/atom-solid Major
@effect/atom-vue Major
@effect/sql-clickhouse Major
@effect/sql-d1 Major
@effect/sql-libsql Major
@effect/sql-mssql Major
@effect/sql-mysql2 Major
@effect/sql-pg Major
@effect/sql-pglite Major
@effect/sql-sqlite-bun Major
@effect/sql-sqlite-do Major
@effect/sql-sqlite-node Major
@effect/sql-sqlite-react-native Major
@effect/sql-sqlite-wasm Major
@effect/openapi-generator Major
@effect/docgen Major
@effect/doctest Major

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

@effect-slopcop effect-slopcop Bot added 4.0 enhancement New feature or request labels Jul 30, 2026
@tim-smart
tim-smart enabled auto-merge (squash) July 30, 2026 21:17

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Semaphore.takeIfAvailable instance method — acquires the specified number of permits only if they are immediately available, returning Effect<boolean>. Implementation follows the existing take pattern with internal.suspend for lazy evaluation and a synchronous check-and-increment that is safe under cooperative Effect scheduling.
  • Module-level Semaphore.takeIfAvailable dual function — matches the signature and dual(2, …) pattern used by take and release.
  • 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 @see cross-references to take, release, and withPermitsIfAvailable.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) (Kimi K2 not used — the program covers this model; add its provider key to run your pick) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes since prior review

  • .changeset/add-semaphore-take-if-available.md — well-formed minor changeset for the new Semaphore.takeIfAvailable API.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) (Kimi K2 not used — the program covers this model; add its provider key to run your pick) | 𝕏

@github-actions

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
basic.ts 6.63 KB 6.63 KB 0.00 KB (0.00%)
batching.ts 9.42 KB 9.42 KB 0.00 KB (0.00%)
brand.ts 6.31 KB 6.31 KB 0.00 KB (0.00%)
cache.ts 10.12 KB 10.12 KB 0.00 KB (0.00%)
config.ts 20.04 KB 20.04 KB 0.00 KB (0.00%)
differ.ts 19.93 KB 19.93 KB 0.00 KB (0.00%)
http-client.ts 20.94 KB 20.94 KB 0.00 KB (0.00%)
logger.ts 10.28 KB 10.28 KB 0.00 KB (0.00%)
metric.ts 8.55 KB 8.55 KB 0.00 KB (0.00%)
optic.ts 7.33 KB 7.33 KB 0.00 KB (0.00%)
pubsub.ts 14.26 KB 14.26 KB 0.00 KB (0.00%)
queue.ts 11.09 KB 11.09 KB 0.00 KB (0.00%)
schedule.ts 10.27 KB 10.27 KB 0.00 KB (0.00%)
schema-class.ts 18.86 KB 18.86 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 28.67 KB 28.67 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 24.99 KB 24.99 KB 0.00 KB (0.00%)
schema-string-transformation.ts 12.95 KB 12.95 KB 0.00 KB (0.00%)
schema-string.ts 10.65 KB 10.65 KB 0.00 KB (0.00%)
schema-template-literal.ts 14.85 KB 14.85 KB 0.00 KB (0.00%)
schema-toArbitraryLazy.ts 21.66 KB 21.66 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 24.08 KB 24.08 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 18.91 KB 18.91 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 18.73 KB 18.73 KB 0.00 KB (0.00%)
schema-toFormatter.ts 18.59 KB 18.59 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 22.33 KB 22.33 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 19.25 KB 19.25 KB 0.00 KB (0.00%)
schema.ts 18.12 KB 18.12 KB 0.00 KB (0.00%)
stm.ts 12.05 KB 12.05 KB 0.00 KB (0.00%)
stream.ts 9.37 KB 9.37 KB 0.00 KB (0.00%)

@tim-smart
tim-smart merged commit b2f95a9 into main Jul 30, 2026
17 checks passed
@tim-smart
tim-smart deleted the agent/codex-engineer/81b3d1db branch July 30, 2026 21:22
@github-project-automation github-project-automation Bot moved this from Discussion Ongoing to Done in PR Backlog Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.0 enhancement New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Semaphore: non-blocking manual acquisition (takeIfAvailable)

1 participant