Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-subscription-ref-get-and-update-some.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

Fix `SubscriptionRef.getAndUpdateSome` to return the current value when no update is selected.
2 changes: 1 addition & 1 deletion packages/effect/src/SubscriptionRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ export const getAndUpdateSome: {
const current = self.value
const option = update(current)
if (Option.isNone(option)) {
return Effect.succeed(current)
return current
}
setUnsafe(self, option.value)
return current
Expand Down
10 changes: 9 additions & 1 deletion packages/effect/test/SubscriptionRef.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assert, describe, it } from "@effect/vitest"
import { Array, Effect, Exit, Fiber, Latch, Number, Pull, Random, Stream, SubscriptionRef } from "effect"
import { Array, Effect, Exit, Fiber, Latch, Number, Option, Pull, Random, Stream, SubscriptionRef } from "effect"

describe("SubscriptionRef", () => {
it.effect("isSubscriptionRef", () =>
Expand All @@ -17,6 +17,14 @@ describe("SubscriptionRef", () => {
assert.strictEqual(yield* SubscriptionRef.get(ref), 2)
}))

it.effect("getAndUpdateSome returns the current value when no update is selected", () =>
Effect.gen(function*() {
const ref = yield* SubscriptionRef.make(1)
const previous = yield* SubscriptionRef.getAndUpdateSome(ref, () => Option.none())

assert.strictEqual(previous, 1)
}))

it.effect("multiple subscribers can receive changes", () =>
Effect.gen(function*() {
const ref = yield* SubscriptionRef.make(0)
Expand Down
Loading