func (sr SubscriptionRegister) AddSubscription(clientId string, patterns []string) { sr.mutex.Lock() defer sr.mutex.Unlock() for _, pattern := range patterns { _, ok := sr.clientByPattern[pattern] if !ok { sr.clientByPattern[pattern] = utils.NewStringSet() } sr.clientByPattern[pattern].Add(clientId) } _, ok := sr.patternsByClient[clientId] if !ok { sr.patternsByClient[clientId] = utils.NewStringSet() } sr.patternsByClient[clientId].AddMany(patterns) }
func (sr SubscriptionRegister) GetClients(patterns []string) []string { StringSet := utils.NewStringSet() sr.mutex.RLock() defer sr.mutex.RUnlock() for _, pattern := range patterns { StringSet.AddMany(sr.clientByPattern[pattern].GetAll()) } return StringSet.GetAll() }