joque
task orchestration library
exec_coro.hpp
Go to the documentation of this file.
1 #pragma once
23 
24 #include "records.hpp"
25 
26 #include <chrono>
27 #include <coroutine>
28 #include <exception>
29 #include <optional>
30 
31 namespace joque
32 {
33 
35 class exec_coro
36 {
37 public:
38  struct promise_type;
39 
41  exec_coro( std::coroutine_handle< promise_type > h );
42 
44  exec_coro( exec_coro&& other ) noexcept;
45  exec_coro& operator=( exec_coro&& other ) noexcept;
46 
48  [[nodiscard]] bool done() const;
49 
53  [[nodiscard]] std::optional< exec_record > result();
54 
58  void tick();
59 
64  std::optional< exec_record >
65  run( std::chrono::milliseconds period = std::chrono::milliseconds{ 5 } );
66 
69 
70 private:
71  std::coroutine_handle< promise_type > h_;
72 };
73 
75 {
76  [[nodiscard]] exec_coro get_return_object();
77 
78  [[nodiscard]] std::suspend_always initial_suspend() const;
79 
80  [[nodiscard]] std::suspend_always final_suspend() const noexcept;
81 
83 
85 
87  std::optional< exec_record > value;
88 
90  std::exception_ptr excep;
91 };
92 
93 } // namespace joque
Coroutine representing one execution of entire task set.
Definition: exec_coro.hpp:36
~exec_coro()
Destroys the coroutine if any.
exec_coro(std::coroutine_handle< promise_type > h)
Constructed by the coroutine mechanism from withing the promise type.
std::optional< exec_record > result()
Returns execution record with data on successfull run.
exec_coro & operator=(exec_coro &&other) noexcept
void tick()
Runs one iteration of the execution, either new task is executed or nothing happens due to all thread...
bool done() const
Execution is done after coroutine finishes it's run.
exec_coro(exec_coro &&other) noexcept
Move swaps internal pointers.
std::optional< exec_record > run(std::chrono::milliseconds period=std::chrono::milliseconds{ 5 })
Blocks until coroutine finishes it's run, returns pointer to exec_record with exact same behavior as ...
MIT License.
Definition: dag.hpp:27
Record of execution of entire task set.
Definition: records.hpp:90
Definition: exec_coro.hpp:75
void return_value(exec_record rec)
std::suspend_always final_suspend() const noexcept
std::optional< exec_record > value
Value returned at the end of execution.
Definition: exec_coro.hpp:87
std::exception_ptr excep
Potential exception raised from within the coroutine.
Definition: exec_coro.hpp:90
std::suspend_always initial_suspend() const