AsyncFw 1.2
Async Framework is c++ runtime with timers, poll notifiers, sockets, coroutines, etc.
 
Loading...
Searching...
No Matches
ContainerTask/main.cpp

Task in container example

/*
Copyright (c) 2026 Alexandr Kuzmuk
This file is part of the AsyncFw project. Licensed under the MIT License.
See {Link: LICENSE file https://mit-license.org} in the project root for full license information.
*/
#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);
}
timer.timeout([&tasks]() {
if (tasks.empty()) {
AsyncFw::MainThread::exit(0);
return;
}
lsInfoGreen() << tasks.front()->running();
(*tasks.front())();
lsInfoGreen() << tasks.front()->running();
tasks.pop();
});
thread.start();
timer.start(50);
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