uvco 0.1
Loading...
Searching...
No Matches
uvco::TaskSet Class Referenceabstract

#include <combinators.h>

Inheritance diagram for uvco::TaskSet:

Public Types

using Id = size_t
using ErrorCallback = std::function<void(Id, std::exception_ptr)>

Public Member Functions

 TaskSet ()=default
 TaskSet (const TaskSet &)=delete
 TaskSet (TaskSet &&) noexcept=default
TaskSetoperator= (const TaskSet &)=delete
TaskSetoperator= (TaskSet &&) noexcept=default
virtual ~TaskSet ()=default
virtual Id add (Promise< void > task)=0
virtual bool empty ()=0
 Check if there are any active tasks on the TaskSet.
virtual Promise< void > onEmpty ()=0
virtual void setOnError (ErrorCallback callback)=0

Static Public Member Functions

static std::unique_ptr< TaskSetcreate ()

Detailed Description

TaskSet handles the common case of maintaining a set of coroutines running in the background which should not be cancelled, but should be cleaned up after finishing.

Member Typedef Documentation

◆ ErrorCallback

using uvco::TaskSet::ErrorCallback = std::function<void(Id, std::exception_ptr)>

◆ Id

using uvco::TaskSet::Id = size_t

Constructor & Destructor Documentation

◆ TaskSet() [1/3]

uvco::TaskSet::TaskSet ( )
default

◆ TaskSet() [2/3]

uvco::TaskSet::TaskSet ( const TaskSet & )
delete

◆ TaskSet() [3/3]

uvco::TaskSet::TaskSet ( TaskSet && )
defaultnoexcept

◆ ~TaskSet()

virtual uvco::TaskSet::~TaskSet ( )
virtualdefault

Member Function Documentation

◆ add()

virtual Id uvco::TaskSet::add ( Promise< void > task)
pure virtual

Add a task to the TaskSet. It will be run to completion. If an exception is thrown, it is printed to stderr, or an ErrorCallback will be called if set before using setOnError().

Implemented in uvco::anonymous_namespace{combinators.cc}::TaskSetImpl.

◆ create()

std::unique_ptr< TaskSet > uvco::TaskSet::create ( )
static

Create a new TaskSet, which can be used to hold a set of background tasks, cleaning up resources of finished tasks automatically.

The implementation is hidden in the .cc file to hide complexity from units including this header.

163 {
164 return std::make_unique<TaskSetImpl>();
165}

◆ empty()

virtual bool uvco::TaskSet::empty ( )
pure virtual

Check if there are any active tasks on the TaskSet.

Implemented in uvco::anonymous_namespace{combinators.cc}::TaskSetImpl.

◆ onEmpty()

virtual Promise< void > uvco::TaskSet::onEmpty ( )
pure virtual

Return a Promise which will be fulfilled when no tasks are left on the TaskSet. Multiple calls to this will return Promise instances which will become ready simultaneously; this means that depending on the scheduling order, by the time this Promise resolves, the TaskSet instance may not be empty anymore.

Implemented in uvco::anonymous_namespace{combinators.cc}::TaskSetImpl.

◆ operator=() [1/2]

TaskSet & uvco::TaskSet::operator= ( const TaskSet & )
delete

◆ operator=() [2/2]

TaskSet & uvco::TaskSet::operator= ( TaskSet && )
defaultnoexcept

◆ setOnError()

virtual void uvco::TaskSet::setOnError ( ErrorCallback callback)
pure virtual

Register a callback which handles errors thrown by tasks. By default, errors are logged to stderr. The callback is called when a task finishes by throwing an exception.

Implemented in uvco::anonymous_namespace{combinators.cc}::TaskSetImpl.


The documentation for this class was generated from the following files: