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

Function main

examples/server_theme/on_transfer.cpp:91–130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89}
90
91auto main() -> int
92{
93 // Create a thread pool and get a scheduler from it
94 exec::static_thread_pool work_pool{8};
95 ex::scheduler auto work_sched = work_pool.get_scheduler();
96
97 exec::static_thread_pool io_pool{1};
98 ex::scheduler auto io_sched = io_pool.get_scheduler();
99
100 std::array<std::byte, 16 * 1024> buffer;
101
102 exec::async_scope scope;
103
104 // Fake a couple of requests
105 for (int i = 0; i < 10; i++)
106 {
107 int sock = i;
108 auto buf = reinterpret_cast<char*>(&buffer[0]);
109
110 // A sender that just calls the legacy read function
111 auto snd_read = ex::just(sock, buf, buffer.size()) | ex::then(legacy_read_from_socket);
112 // The entire flow
113 auto snd =
114 // start by reading data on the I/O thread
115 ex::starts_on(io_sched, std::move(snd_read))
116 // do the processing on the worker threads pool
117 | ex::continues_on(work_sched)
118 // process the incoming data (on worker threads)
119 | ex::then([buf](size_t read_len) { process_read_data(buf, read_len); })
120 // done
121 ;
122
123 // execute the whole flow asynchronously
124 scope.spawn(std::move(snd));
125 }
126
127 (void) stdexec::sync_wait(scope.on_empty());
128
129 return 0;
130}

Callers

nothing calls this directly

Calls 6

thenFunction · 0.85
process_read_dataFunction · 0.85
spawnMethod · 0.80
on_emptyMethod · 0.80
get_schedulerMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected