MCPcopy Create free account
hub / github.com/NVIDIA/stdexec / main

Function main

examples/server_theme/then_upon.cpp:188–228  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

186}
187
188auto 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}

Callers

nothing calls this directly

Calls 6

handle_classify_requestFunction · 0.85
thenFunction · 0.85
spawnMethod · 0.80
on_emptyMethod · 0.80
get_schedulerMethod · 0.45
request_stopMethod · 0.45

Tested by

no test coverage detected