| 407 | } |
| 408 | |
| 409 | server_response_reader::batch_response server_response_reader::wait_for_all(const std::function<bool()> & should_stop) { |
| 410 | batch_response batch_res; |
| 411 | batch_res.results.clear(); |
| 412 | batch_res.results.resize(id_tasks.size()); |
| 413 | while (has_next()) { |
| 414 | auto res = next(should_stop); |
| 415 | if (res == nullptr) { |
| 416 | batch_res.is_terminated = true; |
| 417 | return batch_res; |
| 418 | } |
| 419 | if (res->is_error()) { |
| 420 | batch_res.error = std::move(res); |
| 421 | return batch_res; |
| 422 | } |
| 423 | const size_t idx = res->index; |
| 424 | GGML_ASSERT(idx < batch_res.results.size() && "index out of range"); |
| 425 | GGML_ASSERT(batch_res.results[idx] == nullptr && "duplicate result received"); |
| 426 | batch_res.results[idx] = std::move(res); |
| 427 | } |
| 428 | return batch_res; |
| 429 | } |
| 430 | |
| 431 | void server_response_reader::stop() { |
| 432 | queue_results.remove_waiting_task_ids(id_tasks); |
no test coverage detected