MCPcopy Create free account
hub / github.com/CPChain/chain / execBatch

Method execBatch

api/rpc/server.go:349–372  ·  view source on GitHub ↗

execBatch executes the given requests and writes the result back using the codec. It will only write the response back when the last request is processed.

(ctx context.Context, codec ServerCodec, requests []*serverRequest)

Source from the content-addressed store, hash-verified

347// execBatch executes the given requests and writes the result back using the codec.
348// It will only write the response back when the last request is processed.
349func (s *Server) execBatch(ctx context.Context, codec ServerCodec, requests []*serverRequest) {
350 responses := make([]interface{}, len(requests))
351 var callbacks []func()
352 for i, req := range requests {
353 if req.err != nil {
354 responses[i] = codec.CreateErrorResponse(&req.id, req.err)
355 } else {
356 var callback func()
357 if responses[i], callback = s.handle(ctx, codec, req); callback != nil {
358 callbacks = append(callbacks, callback)
359 }
360 }
361 }
362
363 if err := codec.Write(responses); err != nil {
364 log.Error(fmt.Sprintf("%v\n", err))
365 codec.Close()
366 }
367
368 // when request holds one of more subscribe requests this allows these subscriptions to be activated
369 for _, c := range callbacks {
370 c()
371 }
372}
373
374// readRequest requests the next (batch) request from the codec. It will return the collection
375// of requests, an indication if the request was a batch, the invalid request identifier and an

Callers 1

serveRequestMethod · 0.95

Calls 5

handleMethod · 0.95
CreateErrorResponseMethod · 0.65
WriteMethod · 0.65
ErrorMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected