Skip to content

Commit

Permalink
cycle detection!
Browse files Browse the repository at this point in the history
  • Loading branch information
wcharczuk committed Feb 19, 2024
1 parent 1660054 commit 2c8a37b
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1172,3 +1172,38 @@ func Test_Bind_observedInner_cached(t *testing.T) {
testutil.Equal(t, "bb-b-value", obb.Value())
testutil.Equal(t, "bb-b-value", obo.Value())
}

func Test_Bind_cycle(t *testing.T) {
ctx := testContext()
g := New()

var b1 BindIncr[string]

b0v := Var(g, "a")
b0 := Bind(g, b0v, func(bs Scope, which string) Incr[string] {
if which == "a" {
return Return(bs, "foo")
}
return b1
})

b1v := Var(g, "a")
b1 = Bind(g, b1v, func(bs Scope, which string) Incr[string] {
if which == "a" {
return b0
}
return Return(bs, "bar")
})

o := MustObserve(g, b1)

err := g.Stabilize(ctx)
testutil.NoError(t, err)
testutil.Equal(t, "foo", o.Value())

b0v.Set("b")

err = g.Stabilize(ctx)
testutil.Error(t, err)
testutil.Equal(t, "foo", o.Value())
}

0 comments on commit 2c8a37b

Please sign in to comment.