Skip to content

Add optional acquisition APIs to RcMap and LayerMap - #7411

Merged
tim-smart merged 3 commits into
Effect-TS:mainfrom
altendky:rcmap-get-option
Aug 24, 2026
Merged

tim-smart merged 3 commits into
Effect-TS:mainfrom
altendky:rcmap-get-option

Conversation

@altendky

Copy link
Copy Markdown
Contributor

Type

Feature

Description

Adds RcMap.getOption with data-first and data-last overloads for atomically retaining an entry only when it is already cached. A missing key returns Option.none without invoking lookup or performing capacity acquisition. Existing ready or in-flight entries use the normal reference count and caller-scope finalizer, cached failures propagate unchanged, and closed maps interrupt.

This avoids the race inherent in composing has and get, where the entry can disappear between operations and get can start a new lookup.

Adds LayerMap.contextEffectOption as the direct optional counterpart to contextEffect on both LayerMap instances and generated LayerMap.Service classes. Option.none means the context is not currently cached on an open map, and missing entries do not build a layer.

The change does not modify existing release, TTL, invalidation, or capacity behavior. It includes API lifecycle coverage for missing entries, ready retention and release, in-flight sharing, cached failures, TTL retention and expiry, invalidation linearization, closed-map interruption, and direct and Service LayerMap accessors. It also includes an effect patch changeset.

Validation:

  • pnpm lint-fix
  • 21 targeted RcMap and LayerMap tests passed
  • 11 RcMap and LayerMap doctests passed
  • pnpm check
  • git diff --check
  • pnpm jsdocs --check reports only pre-existing unrelated repository diagnostics; neither changed source module is reported

Related

No related issue.

@changeset-bot

changeset-bot Bot commented Aug 22, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e6b74b2

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

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

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

@github-actions

github-actions Bot commented Aug 22, 2026 •

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.96 KB 6.96 KB 0.00 KB (0.00%)
batching.ts 9.81 KB 9.81 KB 0.00 KB (0.00%)
brand.ts 6.55 KB 6.55 KB 0.00 KB (0.00%)
cache.ts 10.73 KB 10.73 KB 0.00 KB (0.00%)
config.ts 21.49 KB 21.49 KB 0.00 KB (0.00%)
differ.ts 20.32 KB 20.32 KB 0.00 KB (0.00%)
http-client.ts 21.74 KB 21.74 KB 0.00 KB (0.00%)
logger.ts 10.91 KB 10.91 KB 0.00 KB (0.00%)
metric.ts 8.95 KB 8.95 KB 0.00 KB (0.00%)
optic.ts 6.71 KB 6.71 KB 0.00 KB (0.00%)
pubsub.ts 15.09 KB 15.09 KB 0.00 KB (0.00%)
queue.ts 11.77 KB 11.77 KB 0.00 KB (0.00%)
schedule.ts 10.84 KB 10.84 KB 0.00 KB (0.00%)
schema-binary.ts 39.06 KB 39.06 KB 0.00 KB (0.00%)
schema-class.ts 20.08 KB 20.08 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 30.55 KB 30.55 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 26.22 KB 26.22 KB 0.00 KB (0.00%)
schema-string-transformation.ts 13.65 KB 13.65 KB 0.00 KB (0.00%)
schema-string.ts 11.15 KB 11.15 KB 0.00 KB (0.00%)
schema-template-literal.ts 15.45 KB 15.45 KB 0.00 KB (0.00%)
schema-toArbitrary.ts 22.00 KB 22.00 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 24.51 KB 24.51 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 19.28 KB 19.28 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 19.06 KB 19.06 KB 0.00 KB (0.00%)
schema-toFormatter.ts 18.92 KB 18.92 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 23.42 KB 23.42 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 19.54 KB 19.54 KB 0.00 KB (0.00%)
schema.ts 19.25 KB 19.25 KB 0.00 KB (0.00%)
stm.ts 12.72 KB 12.72 KB 0.00 KB (0.00%)
stream.ts 9.78 KB 9.78 KB 0.00 KB (0.00%)

Comment thread packages/effect/src/RcMap.ts Outdated
<K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<Option.Option<A>, E, Scope.Scope> =>
Effect.uninterruptibleMask((restore) => {
if (self.state._tag === "Closed") {
return Effect.interrupt

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.

I think for this case we return None, as no acquisition can happen with this api.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

updated. thanks for taking a look and catching this. i appreciate it.

Return Option.none from RcMap.getOption after closure and align its test and the RcMap and LayerMap documentation with non-acquiring semantics.

Effect-TS#7411 (comment)
@tim-smart
tim-smart merged commit 20cb4f2 into Effect-TS:main Aug 24, 2026
13 of 15 checks passed

This branch had an error being deployed

1 failed deployment
fork — e6b74b23 Deployed Aug 24, 2026 by altendky via approval-gate #12494
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

None yet

Development

Successfully merging this pull request may close these issues.

2 participants