This is a simple task scheduler written in modern C++, using the Async feature.
The scheduler uses promise and future to signal and receive the exit signal.
Method 1:
you can pass just a function to the scheduler, and the scheduler will fire it.
Your function prototype should follow specific guidelines:
First concern, it should be a void function.
second concern, it should have a shared future as a first parameter, and you are free about the other parameters,
that shared future parameter must be there to receive the exit signal from the scheduler.
Method 2:
Pass a class object.
Your class should follow a specific guideline:
There is only one concern about using a task as a class, it should inherit a base class "task_worker", and override its virtual function which will be called by the scheduler.
Kindly find the test to find how to use the scheduler by examples.
Imp Note:
There is something weird that I should mention here,
I have searched the internet about a task scheduler that is implemented using the Async feature, but I couldn't find any.
I'm not sure if there is some sort of evil about using it, but at least it works fine with me up till now.
Async
The Async function is a new feature in modern C++, it saves you the hassle of creating/managing your threads.
Promise, Future
Those are used to communicate objects between threads.
The promise stores a state that the future can monitos to check if there is a signal from the promise or not.
They act a signal sender and receiver.