Skip to content

Commit 92982ec

Browse files
0xh3xtim-smart
andauthored
fix Result to consider waiting flag in equality (#357)
Co-authored-by: Tim Smart <hello@timsmart.co>
1 parent a06ea3e commit 92982ec

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

.changeset/bumpy-pears-push.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@effect-atom/atom": patch
3+
---
4+
5+
fix Result to consider waiting flag in equality

packages/atom/src/Result.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const ResultProto = {
8484
return pipeArguments(this, arguments)
8585
},
8686
[Equal.symbol](this: Result<any, any>, that: Result<any, any>): boolean {
87-
if (this._tag !== that._tag && this.waiting !== that.waiting) {
87+
if (this._tag !== that._tag || this.waiting !== that.waiting) {
8888
return false
8989
}
9090
switch (this._tag) {

packages/atom/test/Atom.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ describe("Atom", () => {
11701170

11711171
// optimistic phase: the optimistic value is set, but the true value is not
11721172
expect(r.get(atom)).toEqual(Result.success(0))
1173-
expect(r.get(optimisticAtom)).toEqual(Result.success(1))
1173+
expect(r.get(optimisticAtom)).toEqual(Result.success(1, { waiting: true }))
11741174

11751175
latch.unsafeOpen()
11761176
await Effect.runPromise(Effect.yieldNow())

packages/atom/test/Result.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as _ from "@effect-atom/atom/Result"
2-
import { Cause } from "effect"
2+
import { Cause, Equal } from "effect"
33
import { describe, expect, it } from "vitest"
44

55
describe("Result", () => {
@@ -14,4 +14,14 @@ describe("Result", () => {
1414
expect(matcher(_.failure(Cause.empty))).toEqual("fail")
1515
expect(matcher(_.success(1))).toEqual(1)
1616
})
17+
18+
it("considers waiting flag in equality", () => {
19+
const success = _.success("value")
20+
const waiting = _.waiting(success)
21+
22+
expect(Equal.isEqual(success)).toBe(true)
23+
expect(Equal.isEqual(waiting)).toBe(true)
24+
expect(Equal.equals(success, waiting)).toBe(false)
25+
expect((success as any)[Equal.symbol](waiting)).toBe(false)
26+
})
1727
})

0 commit comments

Comments
 (0)