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

Function main

examples/hello_world.cpp:26–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24using stdexec::sync_wait;
25
26auto main() -> int
27{
28 exec::static_thread_pool ctx{8};
29 scheduler auto sch = ctx.get_scheduler(); // 1
30
31 sender auto begin = schedule(sch); // 2
32 sender auto hi_again = then( // 3
33 begin, // 3
34 [] { // 3
35 std::cout << "Hello world! Have an int.\n"; // 3
36 return 13; // 3
37 }); // 3
38
39 sender auto add_42 = then(hi_again, [](int arg) { return arg + 42; }); // 4
40 auto [i] = sync_wait(std::move(add_42)).value(); // 5
41 std::cout << "Result: " << i << std::endl;
42
43 // Sync_wait provides a run_loop scheduler
44 std::tuple<run_loop::scheduler> t = sync_wait(get_scheduler()).value();
45 (void) t;
46
47 auto y = let_value(get_scheduler(),
48 [](auto sched)
49 {
50 return starts_on(sched,
51 then(just(),
52 []
53 {
54 std::cout << "from run_loop\n";
55 return 42;
56 }));
57 });
58 sync_wait(std::move(y));
59
60 sync_wait(when_all(just(42), get_scheduler(), get_stop_token()));
61}

Callers

nothing calls this directly

Calls 5

thenFunction · 0.85
scheduleFunction · 0.50
get_schedulerFunction · 0.50
get_schedulerMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected