Update multisub.go

This commit is contained in:
forkfury 2025-12-09 19:38:40 +01:00 committed by GitHub
parent e58c785424
commit 8026d6dbf1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -19,6 +19,13 @@ package event
// JoinSubscriptions joins multiple subscriptions to be able to track them as
// one entity and collectively cancel them or consume any errors from them.
func JoinSubscriptions(subs ...Subscription) Subscription {
// Handle empty subscription list to avoid blocking forever
if len(subs) == 0 {
return NewSubscription(func(unsubbed <-chan struct{}) error {
<-unsubbed
return nil
})
}
return NewSubscription(func(unsubbed <-chan struct{}) error {
// Unsubscribe all subscriptions before returning
defer func() {