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

Function snippetForWakeUp2

Tests/Libraries/Async/AsyncTest.cpp:329–348  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

327}
328
329SC::Result snippetForWakeUp2(AsyncEventLoop& eventLoop, Console& console)
330{
331//! [AsyncLoopWakeUpSnippet2]
332// Assuming an already created (and running) AsyncEventLoop named eventLoop
333// ...
334// This code runs on some different thread from the one calling SC::AsyncEventLoop::run.
335// The callback is invoked from the thread calling SC::AsyncEventLoop::run
336AsyncLoopWakeUp wakeUpWaiting; // Memory lifetime must be valid until callback is called
337wakeUpWaiting.callback = [&](AsyncLoopWakeUp::Result& result)
338{
339 console.print("My wakeUp has been called!");
340 result.reactivateRequest(true); // To allow waking-up it again later
341};
342EventObject eventObject;
343SC_TRY(wakeUpWaiting.start(eventLoop, eventObject));
344eventObject.wait(); // Wait until callback has been fully run inside event loop thread
345// From here on we know for sure that callback has been called
346//! [AsyncLoopWakeUpSnippet2]
347return Result(true);
348}
349
350SC::Result snippetForProcess(AsyncEventLoop& eventLoop, Console& console)
351{

Callers

nothing calls this directly

Calls 5

printMethod · 0.80
reactivateRequestMethod · 0.80
ResultClass · 0.50
startMethod · 0.45
waitMethod · 0.45

Tested by

no test coverage detected