Skip to content

Commit e6b74b2

Browse files
committed
review comment: return None from closed RcMap
Return Option.none from RcMap.getOption after closure and align its test and the RcMap and LayerMap documentation with non-acquiring semantics. #7411 (comment)
1 parent b328b12 commit e6b74b2

3 files changed

Lines changed: 12 additions & 24 deletions

File tree

‎packages/effect/src/LayerMap.ts‎

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,8 @@ export interface LayerMap<in out K, in out I, in out E = never> {
9898
*
9999
* **Details**
100100
*
101-
* For an open `LayerMap`, `Option.none` means no entry is currently cached; no
102-
* layer is built for a missing key. An existing in-flight entry is awaited.
103-
*
104-
* **Gotchas**
105-
*
106-
* A closed `LayerMap` interrupts instead of returning `Option.none`.
101+
* `Option.none` means no entry is currently cached or the `LayerMap` is closed;
102+
* no layer is built for a missing key. An existing in-flight entry is awaited.
107103
*
108104
* @since 4.0.0
109105
*/
@@ -339,12 +335,8 @@ export interface TagClass<
339335
*
340336
* **Details**
341337
*
342-
* For an open `LayerMap`, `Option.none` means no entry is currently cached; no
343-
* layer is built for a missing key. An existing in-flight entry is awaited.
344-
*
345-
* **Gotchas**
346-
*
347-
* A closed `LayerMap` interrupts instead of returning `Option.none`.
338+
* `Option.none` means no entry is currently cached or the `LayerMap` is closed;
339+
* no layer is built for a missing key. An existing in-flight entry is awaited.
348340
*
349341
* @since 4.0.0
350342
*/

‎packages/effect/src/RcMap.ts‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -393,14 +393,11 @@ export const get: {
393393
*
394394
* **Details**
395395
*
396-
* On an open map, returns `Option.none` when the key is not currently stored. If
397-
* an entry exists, its reference count is incremented for the current `Scope`
398-
* before awaiting its result. A successful entry returns `Option.some(value)`,
399-
* while an in-flight or cached failure fails with the same error as `get`.
400-
*
401-
* **Gotchas**
402-
*
403-
* A closed map interrupts instead of returning `Option.none`.
396+
* Returns `Option.none` when the key is not currently stored or the map is
397+
* closed. If an entry exists, its reference count is incremented for the current
398+
* `Scope` before awaiting its result. A successful entry returns
399+
* `Option.some(value)`, while an in-flight or cached failure fails with the same
400+
* error as `get`.
404401
*
405402
* **Example** (Retaining only cached resources)
406403
*
@@ -437,7 +434,7 @@ export const getOption: {
437434
<K, A, E>(self: RcMap<K, A, E>, key: K): Effect.Effect<Option.Option<A>, E, Scope.Scope> =>
438435
Effect.uninterruptibleMask((restore) => {
439436
if (self.state._tag === "Closed") {
440-
return Effect.interrupt
437+
return Effect.succeedNone
441438
}
442439
const o = MutableHashMap.get(self.state.map, key)
443440
if (o._tag === "None") {

‎packages/effect/test/RcMap.test.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,15 @@ describe("RcMap", () => {
161161
assert.strictEqual(yield* Ref.get(released), 1)
162162
}))
163163

164-
it.effect("interrupts when the map is closed", () =>
164+
it.effect("returns None when the map is closed", () =>
165165
Effect.gen(function*() {
166166
const mapScope = yield* Scope.make()
167167
const map = yield* RcMap.make({
168168
lookup: (key: string) => Effect.succeed(key)
169169
}).pipe(Scope.provide(mapScope))
170170
yield* Scope.close(mapScope, Exit.void)
171171

172-
const exit = yield* RcMap.getOption(map, "key").pipe(Effect.exit)
173-
assert.isTrue(Exit.hasInterrupts(exit))
172+
assert.deepStrictEqual(yield* RcMap.getOption(map, "key"), Option.none())
174173
}))
175174
})
176175

0 commit comments

Comments
 (0)