| 186 | } |
| 187 | |
| 188 | auto main() -> int |
| 189 | { |
| 190 | // Create a thread pool and get a scheduler from it |
| 191 | exec::async_scope scope; |
| 192 | exec::static_thread_pool pool{8}; |
| 193 | ex::scheduler auto sched = pool.get_scheduler(); |
| 194 | |
| 195 | // Fake a couple of requests |
| 196 | for (int i = 0; i < 12; i++) |
| 197 | { |
| 198 | // Create a test request |
| 199 | char const * body = ""; |
| 200 | if (i % 2 == 0) |
| 201 | body = "human"; |
| 202 | else if (i % 3 == 0) |
| 203 | body = "cat"; |
| 204 | else if (i % 5 == 0) |
| 205 | body = "dog"; |
| 206 | else if (i % 7 == 0) |
| 207 | body = "bird"; |
| 208 | http_request req{.url_ = "/classify", .headers_ = {}, .body_ = body}; |
| 209 | |
| 210 | // The handler for the "classify" requests |
| 211 | ex::sender auto snd = handle_classify_request(req); |
| 212 | |
| 213 | // Pack this into a simplified flow and execute it asynchronously |
| 214 | ex::sender auto action = std::move(snd) |
| 215 | | ex::then( |
| 216 | [](http_response resp) |
| 217 | { |
| 218 | std::ostringstream oss; |
| 219 | oss << "Sending response: " << resp.status_code_ << " / " |
| 220 | << resp.body_ << "\n"; |
| 221 | std::cout << oss.str(); |
| 222 | }); |
| 223 | scope.spawn(ex::starts_on(sched, std::move(action))); |
| 224 | } |
| 225 | |
| 226 | stdexec::sync_wait(scope.on_empty()); |
| 227 | pool.request_stop(); |
| 228 | } |
nothing calls this directly
no test coverage detected