MCPcopy Index your code
hub / github.com/github/copilot-sdk / getOrCreateExchange

Method getOrCreateExchange

go/copilot_request_handler.go:570–580  ·  view source on GitHub ↗

getOrCreateExchange returns the exchange for requestID, allocating one if it does not yet exist. The runtime dispatches httpRequestStart and httpRequestChunk frames on separate goroutines (see jsonrpc2.handleRequest), so a body chunk — including the terminal end frame — can arrive before its start f

(requestID string)

Source from the content-addressed store, hash-verified

568// first touch means those chunks are buffered rather than dropped, instead of
569// hanging the body drain forever.
570func (a *copilotRequestAdapter) getOrCreateExchange(requestID string) *pendingExchange {
571 a.mu.Lock()
572 defer a.mu.Unlock()
573 if exchange, ok := a.pending[requestID]; ok {
574 return exchange
575 }
576 ctx, cancel := context.WithCancel(context.Background())
577 exchange := &pendingExchange{queue: newFrameQueue(), ctx: ctx, cancel: cancel}
578 a.pending[requestID] = exchange
579 return exchange
580}
581
582func (a *copilotRequestAdapter) HttpRequestStart(params *rpc.LlmInferenceHTTPRequestStartRequest) (*rpc.LlmInferenceHTTPRequestStartResult, error) {
583 // Adopt any exchange a racing chunk already created — with its buffered

Callers 2

HttpRequestStartMethod · 0.95
HttpRequestChunkMethod · 0.95

Calls 1

newFrameQueueFunction · 0.85

Tested by

no test coverage detected