MCPcopy Create free account
hub / github.com/cel-expr/cel-go / getOrCreate

Method getOrCreate

interpreter/async.go:223–248  ·  view source on GitHub ↗

getOrCreate returns the existing call state for the (node id, args) tuple, or registers and returns a new one. A newly registered call is assigned a unique callID and counted as pending.

(id int64, function, overload string, argVals []ref.Val, impl functions.AsyncOp, gate *asyncGate)

Source from the content-addressed store, hash-verified

221// getOrCreate returns the existing call state for the (node id, args) tuple, or registers and
222// returns a new one. A newly registered call is assigned a unique callID and counted as pending.
223func (t *asyncCallStateTracker) getOrCreate(id int64, function, overload string, argVals []ref.Val, impl functions.AsyncOp, gate *asyncGate) *asyncCallState {
224 key := hashCall(id, overload, argVals)
225
226 t.mu.RLock()
227 acs := findInBucket(t.calls[key], id, function, overload, argVals)
228 t.mu.RUnlock()
229 if acs != nil {
230 return acs
231 }
232
233 t.mu.Lock()
234 defer t.mu.Unlock()
235 // Check again in case it was created while waiting for the lock.
236 if acs := findInBucket(t.calls[key], id, function, overload, argVals); acs != nil {
237 return acs
238 }
239
240 // Assign a new unique call ID for this async call.
241 acs = newAsyncCallState(id, function, overload, argVals, impl)
242 callID := t.nextCallID.Add(1)
243 acs.callID = callID
244 acs.gate = gate
245 t.calls[key] = append(t.calls[key], acs)
246 t.callsByID[callID] = acs
247 return acs
248}
249
250func (t *asyncCallStateTracker) getByID(callID int64) *asyncCallState {
251 t.mu.RLock()

Calls 4

hashCallFunction · 0.85
findInBucketFunction · 0.85
newAsyncCallStateFunction · 0.85
AddMethod · 0.65