Lely core libraries  2.2.5
co_task.hpp
Go to the documentation of this file.
1 
24 #ifndef LELY_EV_CO_TASK_HPP_
25 #define LELY_EV_CO_TASK_HPP_
26 
27 #include <lely/ev/exec.hpp>
28 #include <lely/util/coroutine.hpp>
29 
30 namespace lely {
31 namespace ev {
32 
34 class CoTask : public ev_task, public util::Coroutine {
35  public:
37  explicit CoTask(ev_exec_t* exec) noexcept
38  : ev_task EV_TASK_INIT(exec, [](ev_task * task) noexcept {
39  auto self = static_cast<CoTask*>(task);
40  (*self)();
41  }) {}
42 
44  CoTask() noexcept : CoTask(nullptr) {}
45 
46  virtual ~CoTask() = default;
47 
49  Executor
50  get_executor() const noexcept {
51  return Executor(exec);
52  }
53 
55  virtual void operator()() noexcept = 0;
56 };
57 
58 } // namespace ev
59 } // namespace lely
60 
61 #endif // !LELY_EV_CO_TASK_HPP_
const struct ev_exec_vtbl *const ev_exec_t
An abstract task executor.
Definition: ev.h:29
#define EV_TASK_INIT(exec, func)
The static initializer for ev_task.
Definition: task.h:53
This header file is part of the utilities library; it contains the C++ implementation of stackless co...
A stackless coroutine which can be submitted to an executor as a task.
Definition: co_task.hpp:34
The parent class for function objects used as stackless coroutines.
Definition: coroutine.hpp:48
ev_exec_t * exec
A pointer to the executor to which the task is (to be) submitted.
Definition: task.h:43
CoTask(ev_exec_t *exec) noexcept
Constructs a coroutine task with an associated executor (can be nullptr).
Definition: co_task.hpp:37
CoTask() noexcept
Constructs a coroutine task.
Definition: co_task.hpp:44
virtual void operator()() noexcept=0
The coroutine to be executed when the task is run.
This header file is part of the event library; it contains the C++ interface for the abstract task ex...
An executable task.
Definition: task.h:41
Executor get_executor() const noexcept
Returns the executor to which the task is (to be) submitted.
Definition: co_task.hpp:50
An abstract task executor. This class is a wrapper around ev_exec_t*.
Definition: exec.hpp:38
Definition: buf.hpp:32