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)
| 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. |
| 223 | func (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 | |
| 250 | func (t *asyncCallStateTracker) getByID(callID int64) *asyncCallState { |
| 251 | t.mu.RLock() |