libstp
Robotics library for Botball
Loading...
Searching...
No Matches
algorithm.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <coroutine>
4
5namespace libstp::async
6{
8 template <typename T>
10 {
11 public:
14 {
15 bool initialized = false;
16
18
20
21 static std::suspend_always initial_suspend() noexcept;
22
23 static std::suspend_always final_suspend() noexcept;
24
25 void return_value(const T& value);
26
27 static void unhandled_exception();
28
29 std::suspend_always yield_value(const T& value);
30 };
31
32 using handle_type = std::coroutine_handle<promise_type>;
33
35
37
38 AsyncAlgorithm(AsyncAlgorithm&& other) noexcept;
39
41
43 bool advance();
44
46 T current() const;
47
49 [[nodiscard]] bool await_ready() const noexcept;
50
52 void await_suspend(std::coroutine_handle<> awaiting_coro) noexcept;
53
55 T await_resume() noexcept;
56
57 private:
58 handle_type coro;
59 };
60}
bool advance()
Resume the coroutine once. Returns false when the coroutine is finished.
T current() const
Return the last yielded or returned value from the coroutine.
std::coroutine_handle< promise_type > handle_type
Definition algorithm.hpp:32
T await_resume() noexcept
Awaiter API: return the current value after suspension completes.
void await_suspend(std::coroutine_handle<> awaiting_coro) noexcept
Awaiter API: resume the wrapped coroutine, then resume the awaiting coroutine.
bool await_ready() const noexcept
Awaiter API: reports ready only once the wrapped coroutine is done.
Coroutine promise storing the most recent yielded or returned value.
Definition algorithm.hpp:14
static std::suspend_always final_suspend() noexcept
std::suspend_always yield_value(const T &value)
static std::suspend_always initial_suspend() noexcept