MCPcopy Create free account
hub / github.com/Codesire-Deng/co_context / f

Function f

example/stop_token.cpp:24–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22}
23
24task<> f() {
25 // The same as std::stop_source.
26 // See https://en.cppreference.com/w/cpp/header/stop_token
27 stop_source source;
28 stop_token token = source.get_token();
29
30 co_spawn(g(token));
31
32 co_await yield(); // Let `g` starts.
33 source.request_stop(); // Trigger the callback.
34
35 // The `source` and `token` are destroyed before `g` finished.
36 // It is safe to do that.
37 co_return;
38}
39
40int main() {
41 io_context ctx;

Callers 1

mainFunction · 0.70

Calls 5

co_spawnFunction · 0.85
yieldFunction · 0.85
get_tokenMethod · 0.80
gFunction · 0.70
request_stopMethod · 0.45

Tested by

no test coverage detected