#include <AsyncFw/MainThread>
#include <AsyncFw/ThreadPool>
#include <AsyncFw/Coroutine>
#include <AsyncFw/Timer>
#include <AsyncFw/Log>
#define CURRENT_TIME_MS (std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count())
using namespace AsyncFw;
logDebug() << "task started";
ThreadPool::async(
[&_ms]() {
std::this_thread::sleep_for(std::chrono::milliseconds(_ms));
},
[&end, _h]() {
logDebug() << "resume";
end = CURRENT_TIME_MS;
_h.resume();
logDebug() << "resume end";
});
});
logDebug() << "task finished";
}
void tst(int _ms) {
uint64_t tst_time = CURRENT_TIME_MS;
logNotice() << _ms << "start";
uint64_t ms_start = CURRENT_TIME_MS;
logDebug() << _ms << "START" << ms_start;
uint64_t ms_end;
logNotice() << _ms << ms_end - ms_start << "=====" << CURRENT_TIME_MS - tst_time;
}
int main(int argc, char *argv[]) {
AsyncFw::Instance<AsyncFw::ThreadPool>::create("CoroutineWaitExamplePool", 5);
logNotice() << "MainThread::quit()";
MainThread::exit();
});
logNotice() << "MainThread::exec()";
return MainThread::exec();
}
static Thread * currentThread()
Returns a pointer to the AsyncFw::Thread that manages the currently executing thread.
Definition Thread.cpp:32
static void single(int ms, T function)
Starts a single shot timer with the specified timeout.
Definition Timer.h:19
The CoroutineAwait struct.
Definition Coroutine.h:53
The CoroutineTask struct.
Definition Coroutine.h:20
void wait()
Runs nested Thread::exec() and wait for task finished.
Definition Coroutine.cpp:45