Task in container example
#include <queue>
#include <AsyncFw/MainThread>
#include <AsyncFw/Timer>
#include <AsyncFw/Task>
#include <AsyncFw/LogStream>
int main(int argc, char *argv[]) {
std::queue<std::shared_ptr<AsyncFw::AbstractTask>> tasks;
for (int i = 0; i != 10; ++i) {
std::shared_ptr<AsyncFw::AbstractTask> task = std::shared_ptr<AsyncFw::AbstractTask>(
new AsyncFw::Task([](std::any *data) { logInfo() <<
"task:" << std::any_cast<int>(*data); }, &thread));
task->setData(i);
tasks.push(task);
}
if (tasks.empty()) {
AsyncFw::MainThread::exit(0);
return;
}
lsInfoGreen() << tasks.front()->running();
(*tasks.front())();
lsInfoGreen() << tasks.front()->running();
tasks.pop();
});
logNotice() << "Start Applicaiton";
int ret = AsyncFw::MainThread::exec();
logNotice() << "End Applicaiton";
return ret;
}
void start()
Create a managed thread and run exec().
Definition AbstractThread.cpp:636
The Task class.
Definition Task.h:27
AsyncFw::Thread thread with sockets.
Definition Thread.h:16
The Timer class.
Definition Timer.h:15
void start(int, bool=false)
Starts or restarts a timer with the specified timeout. If the timer is already running,...
Definition Timer.cpp:29
FunctionConnectorProtected< Timer >::Connector<> timeout
The Timer::timeout connector.
Definition Timer.h:31