MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / Subscribe

Method Subscribe

pkg/wps/wps.go:75–104  ·  view source on GitHub ↗

if already subscribed, this will *resubscribe* with the new subscription (remove the old one, and replace with this one)

(subRouteId string, sub SubscriptionRequest)

Source from the content-addressed store, hash-verified

73
74// if already subscribed, this will *resubscribe* with the new subscription (remove the old one, and replace with this one)
75func (b *BrokerType) Subscribe(subRouteId string, sub SubscriptionRequest) {
76 // log.Printf("[wps] sub %s %s\n", subRouteId, sub.Event)
77 if sub.Event == "" {
78 return
79 }
80 b.Lock.Lock()
81 defer b.Lock.Unlock()
82 b.unsubscribe_nolock(subRouteId, sub.Event)
83 bs := b.SubMap[sub.Event]
84 if bs == nil {
85 bs = &BrokerSubscription{
86 AllSubs: []string{},
87 ScopeSubs: make(map[string][]string),
88 StarSubs: make(map[string][]string),
89 }
90 b.SubMap[sub.Event] = bs
91 }
92 if sub.AllScopes {
93 bs.AllSubs = utilfn.AddElemToSliceUniq(bs.AllSubs, subRouteId)
94 return
95 }
96 for _, scope := range sub.Scopes {
97 starMatch := scopeHasStarMatch(scope)
98 if starMatch {
99 addStrToScopeMap(bs.StarSubs, scope, subRouteId)
100 } else {
101 addStrToScopeMap(bs.ScopeSubs, scope, subRouteId)
102 }
103 }
104}
105
106func (bs *BrokerSubscription) IsEmpty() bool {
107 return len(bs.AllSubs) == 0 && len(bs.ScopeSubs) == 0 && len(bs.StarSubs) == 0

Callers 1

EventSubCommandMethod · 0.80

Calls 4

unsubscribe_nolockMethod · 0.95
AddElemToSliceUniqFunction · 0.92
scopeHasStarMatchFunction · 0.85
addStrToScopeMapFunction · 0.85

Tested by

no test coverage detected