Skip to content

Commit 23d4d95

Browse files
committed
fix event bus isClosed logic
1 parent d6a1be1 commit 23d4d95

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

event/buffered_bus.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type bufferedBus struct {
3333
subs map[uint64]*Subscription
3434
// events is a mapping of event names to subscriber ids.
3535
events map[Name]map[uint64]struct{}
36-
// commandChannel manages all commands sent to this simpleChannel.
36+
// commandChannel manages all commands sent to the bufferedBus.
3737
//
3838
// It is important that all stuff gets sent through this single channel to ensure
3939
// that the order of operations is preserved.
@@ -90,10 +90,9 @@ func (b *bufferedBus) Unsubscribe(sub *Subscription) {
9090
}
9191

9292
func (b *bufferedBus) Close() {
93-
if b.isClosed.Load() {
93+
if !b.isClosed.CompareAndSwap(false, true) {
9494
return
9595
}
96-
b.isClosed.Store(true)
9796
b.commandChannel <- closeCommand{}
9897
// Wait for the close command to be handled, in order, before returning
9998
<-b.hasClosedChan

0 commit comments

Comments
 (0)