Implement task system to processing data asynchronously
#include "tasker.h"
int main()
{
Tasker<int> tasker { [](auto&& value) { std::cout << value; } };
tasker.Post(42);
return 0;
}
#include "tasker.h"
class A {
public:
A()
: tasker_ { [this](auto&& value) { Process(std::move(value)); } }
{
}
~A()
{
// Need to stop tasker before releasing other member variable
tasker_.Stop();
}
void Send(int value)
{
tasker_.Post(value);
}
private:
void Process(int value)
{
std::cout << value;
}
Tasker<int> tasker_;
};
int main()
{
A a;
a.Send(42);
return 0;
}