problem: panic if calling unsub more than once

problem: panic if calling unsub more than once

It's a bit dangerous if calling unsub more than once causes a fatal panic.
This commit is contained in:
Stan Stacker 2022-12-25 04:58:44 +00:00 committed by fiatjaf
parent 3f2c3f1bd8
commit bb1138a2fa

View File

@ -157,7 +157,15 @@ func (r *RelayPool) Sub(filters Filters) (subID string, events chan EventMessage
return true
})
return id, eventStream, func() { close(unsub) }
return id, eventStream, func() { gracefulClose(unsub) }
}
func gracefulClose(c chan struct{}) {
select {
case <-c:
default:
close(c)
}
}
func Unique(all chan EventMessage) chan Event {