return nullptr if should_stop() is true before receiving a result note: if one error is received, it will stop further processing and return error result
| 376 | // return nullptr if should_stop() is true before receiving a result |
| 377 | // note: if one error is received, it will stop further processing and return error result |
| 378 | server_task_result_ptr server_response_reader::next(const std::function<bool()> & should_stop) { |
| 379 | while (true) { |
| 380 | server_task_result_ptr result = queue_results.recv_with_timeout(id_tasks, polling_interval_seconds); |
| 381 | if (result == nullptr) { |
| 382 | // timeout, check stop condition |
| 383 | if (should_stop()) { |
| 384 | SRV_DBG("%s", "stopping wait for next result due to should_stop condition\n"); |
| 385 | return nullptr; |
| 386 | } |
| 387 | } else { |
| 388 | if (result->is_error()) { |
| 389 | stop(); // cancel remaining tasks |
| 390 | SRV_DBG("%s", "received error result, stopping further processing\n"); |
| 391 | return result; |
| 392 | } |
| 393 | if (!states.empty()) { |
| 394 | // update the generation state if needed |
| 395 | const size_t idx = result->index; |
| 396 | GGML_ASSERT(idx < states.size()); |
| 397 | result->update(states[idx]); |
| 398 | } |
| 399 | if (result->is_stop()) { |
| 400 | received_count++; |
| 401 | } |
| 402 | return result; |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | // should not reach here |
| 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; |
nothing calls this directly
no test coverage detected