MCPcopy Index your code
hub / github.com/dgraph-io/dgraph / newSubscriber

Method newSubscriber

dgraph/cmd/zero/oracle.go:155–174  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

153}
154
155func (o *Oracle) newSubscriber() (<-chan pb.OracleDelta, int) {
156 o.Lock()
157 defer o.Unlock()
158 var id int
159 for {
160 //nolint:gosec // random generator for node id does not require cryptographic precision
161 id = rand.Int()
162 if _, has := o.subscribers[id]; !has {
163 break
164 }
165 }
166
167 // The channel takes a delta instead of a pointer as the receiver needs to
168 // modify it by setting the group checksums. Passing a pointer previously
169 // resulted in a race condition.
170 ch := make(chan pb.OracleDelta, 1000)
171 ch <- *o.currentState() // Queue up the full state as the first entry.
172 o.subscribers[id] = ch
173 return ch, id
174}
175
176func (o *Oracle) removeSubscriber(id int) {
177 o.Lock()

Callers 1

OracleMethod · 0.80

Calls 3

currentStateMethod · 0.95
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected