From 9e53a7e66873b5f57b81087ec3bc17b83b5c14ce Mon Sep 17 00:00:00 2001 From: implausiblyfun Date: Sun, 5 Jun 2022 13:10:46 -0400 Subject: [PATCH] event/internal: Unbind calls now take the current reset of the bus into account --- event/internal.go | 2 +- event/response_test.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/event/internal.go b/event/internal.go index ea692834..4b2e364f 100644 --- a/event/internal.go +++ b/event/internal.go @@ -36,7 +36,7 @@ func (bus *Bus) trigger(binds bindableList, eventID UnsafeEventID, callerID Call // A: This goroutine does not own a write lock on the bus, and should therefore // not modify its contents. We do not have a simple way of promoting our read lock // to a write lock. - bus.Unbind(Binding{EventID: eventID, CallerID: callerID, BindID: bindID}) + bus.Unbind(Binding{EventID: eventID, CallerID: callerID, BindID: bindID, busResetCount: bus.resetCount}) case ResponseUnbindThisCaller: bus.UnbindAllFrom(callerID) } diff --git a/event/response_test.go b/event/response_test.go index 4d3616ec..01fa8dd6 100644 --- a/event/response_test.go +++ b/event/response_test.go @@ -12,6 +12,9 @@ func TestBindingResponses(t *testing.T) { t.Run("UnbindThisBinding", func(t *testing.T) { b := event.NewBus(event.NewCallerMap()) + // bus reset counts are checked against bindings + b.Reset() + var calls int32 b1 := b.UnsafeBind(1, 0, func(ci event.CallerID, h event.Handler, i interface{}) event.Response { atomic.AddInt32(&calls, 1)