template <class Ret>
class AsyncWork
Represents a job that can be executed in another thread and can return a value. It is similar to future/promise pattern, but it allows cancelation and is based on U++ thread pool shared with CoWork. AsyncWork has pick constructor / operator.
template < class Function, class... Args>
void Do(Function&& f, Args&&... args)
Schedules job f with parameters args to be asynchronously performed in (possibly) another thread.
void Cancel()
Cancels the job.
static bool IsCanceled()
Returns true in the job routine if the master AsyncWork was canceled.
bool IsFinished()
Returns true if job was finished.
Ret Get()
Waits for job to be finished (if necessary), then returns the return value of f. If there was exception, it is rethrown.
Ret operator~()
Same as Get().
Ret Pick()
Similar to Get, but uses pick constructor instead of copy constructor to pass the return value.
~AsyncWork()
If work has not be finished, destructor cancels it.
auto Async(Function&& f, Args&&... args)
Returns AsyncWork for given job f with args.
|