Closed
Description
Add a new non-blocking function to schedulers as explained in discussion #126 . E.g.;
class LoopScheduler
{
...
bool ExecOne()
{
std::function<void()> task;
{
std::unique_lock<std::mutex> lck(mtx);
cv.wait(lck, [this](){ return !running || !tasks.empty(); });
if (!running)
return false;
task = tasks.front();
tasks.pop();
}
if (task)
task();
return true;
}
bool PollOne()
{
std::function<void()> task;
{
std::unique_lock<std::mutex> lck(mtx);
if (!running || tasks.empty())
return false;
task = tasks.front();
tasks.pop();
}
if (task)
task();
return true;
}
...
};
class AsioScheduler
{
...
void ExecOne() { context->run_one(); }
void PollOne() { context->poll_one(); }
...
};