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)
| 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. |
| 349 | func (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 |
no test coverage detected