MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / subscribe

Method subscribe

internal/redisqueue/queue.go:162–184  ·  view source on GitHub ↗
(buffer int, initialPayload []byte)

Source from the content-addressed store, hash-verified

160}
161
162func (q *queue) subscribe(buffer int, initialPayload []byte) (<-chan []byte, func()) {
163 subscriber := make(chan []byte, buffer)
164 if len(initialPayload) > 0 {
165 subscriber <- append([]byte(nil), initialPayload...)
166 }
167
168 q.mu.Lock()
169 if q.subscribers == nil {
170 q.subscribers = make(map[uint64]chan []byte)
171 }
172 q.nextSubscriberID++
173 id := q.nextSubscriberID
174 q.subscribers[id] = subscriber
175 q.mu.Unlock()
176
177 var once sync.Once
178 unsubscribe := func() {
179 once.Do(func() {
180 q.unsubscribe(id)
181 })
182 }
183 return subscriber, unsubscribe
184}
185
186func (q *queue) unsubscribe(id uint64) {
187 q.mu.Lock()

Callers 2

SubscribeUsageFunction · 0.80
SubscribeErrorsFunction · 0.80

Calls 2

unsubscribeMethod · 0.95
DoMethod · 0.65

Tested by

no test coverage detected