events: don't explode when destroying a bus

Only attempt to close channels once, rather than per topic
they are subscribed to.
This commit is contained in:
Matthew Penner
2022-01-20 09:48:18 -07:00
parent 6d8c1d2225
commit 4ba5fe2866
4 changed files with 39 additions and 22 deletions

View File

@@ -16,14 +16,6 @@ func newSinkPool() *sinkPool {
return &sinkPool{}
}
// On adds a sink on the pool.
func (p *sinkPool) On(c chan []byte) {
p.mx.Lock()
defer p.mx.Unlock()
p.sinks = append(p.sinks, c)
}
// Off removes a sink from the pool.
func (p *sinkPool) Off(c chan []byte) {
p.mx.Lock()
@@ -39,10 +31,19 @@ func (p *sinkPool) Off(c chan []byte) {
sinks[len(sinks)-1] = nil
sinks = sinks[:len(sinks)-1]
p.sinks = sinks
close(c)
return
}
}
// On adds a sink on the pool.
func (p *sinkPool) On(c chan []byte) {
p.mx.Lock()
defer p.mx.Unlock()
p.sinks = append(p.sinks, c)
}
// Destroy destroys the pool by removing and closing all sinks.
func (p *sinkPool) Destroy() {
p.mx.Lock()