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