MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / snippetForTimeout

Function snippetForTimeout

Tests/Libraries/Async/AsyncTest.cpp:287–309  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

285// ...
286SC_TRY(eventLoop.run());
287// ...
288// Here all AsyncRequest have either finished or have been stopped
289// ...
290SC_TRY(eventLoop.close()); // Free OS specific queue handles
291//! [AsyncEventLoopSnippet]
292return Result(true);
293}
294
295SC::Result snippetForTimeout(AsyncEventLoop& eventLoop, Console& console)
296{
297 bool someCondition = false;
298//! [AsyncLoopTimeoutSnippet]
299// Create a timeout that will be called after 200 milliseconds
300// AsyncLoopTimeout must be valid until callback is called
301AsyncLoopTimeout timeout;
302timeout.callback = [&](AsyncLoopTimeout::Result& res)
303{
304 console.print("My timeout has been called!");
305 if (someCondition) // Optionally re-activate the timeout if needed
306 {
307 // Schedule the timeout callback to fire again 100 ms from now
308 res.getAsync().relativeTimeout = Time::Milliseconds(100);
309 res.reactivateRequest(true);
310 }
311};
312// Start the timeout, that will be called 200 ms from now

Callers

nothing calls this directly

Calls 6

MillisecondsClass · 0.85
printMethod · 0.80
reactivateRequestMethod · 0.80
ResultClass · 0.50
startMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected