mrs_lib
Various reusable classes, functions and utilities for use in MRS projects
Loading...
Searching...
No Matches
task.impl.hpp
1#ifndef MRS_LIB_CORO_TASK_IMPL_HPP_
2#define MRS_LIB_CORO_TASK_IMPL_HPP_
3
4#include <mrs_lib/coro/internal/thread_local_continuation_scheduler.hpp>
5#include <mrs_lib/coro/task.hpp>
6
7namespace mrs_lib
8{
9 namespace internal
10 {
11
12 template <typename Derived>
13 inline bool BasePromiseType<Derived>::FinalAwaitable::await_ready() noexcept
14 {
15 return false;
16 }
17
18 template <typename Derived>
19 inline void BasePromiseType<Derived>::FinalAwaitable::await_suspend(std::coroutine_handle<Derived> task_handle) noexcept
20 {
21 // Destructor of task would destroy the continuation so we need to release the continuation
22 schedule_coroutine_continuation(task_handle.promise().continuation_.release());
23 }
24
25 template <typename Derived>
26 inline void BasePromiseType<Derived>::FinalAwaitable::await_resume() noexcept
27 {
28 assert(false);
29 }
30
31 template <typename Derived>
32 inline std::suspend_always BasePromiseType<Derived>::initial_suspend()
33 {
34 return {};
35 }
36
37 template <typename Derived>
38 inline auto BasePromiseType<Derived>::final_suspend() noexcept -> FinalAwaitable
39 {
40 return {};
41 }
42
43 template <typename Derived>
44 inline void BasePromiseType<Derived>::set_continuation(OwningCoroutineHandle<> continuation)
45 {
46 continuation_ = std::move(continuation);
47 }
48
49 template <typename T>
50 Task<T> PromiseType<T>::get_return_object()
51 {
52 return Task<T>(OwningCoroutineHandle<PromiseType>(std::coroutine_handle<PromiseType>::from_promise(*this)));
53 }
54
55 template <typename T>
56 void PromiseType<T>::return_value(T&& ret_val)
57 {
58 result_.set_value(std::move(ret_val));
59 }
60
61 template <typename T>
62 void PromiseType<T>::unhandled_exception()
63 {
64 result_.set_exception(std::current_exception());
65 }
66
67 inline Task<void> PromiseType<void>::get_return_object()
68 {
69 return Task<void>(OwningCoroutineHandle<PromiseType>(std::coroutine_handle<PromiseType>::from_promise(*this)));
70 }
71
72 inline void PromiseType<void>::return_void()
73 {
74 }
75
76 inline void PromiseType<void>::unhandled_exception()
77 {
78 exception_ = std::current_exception();
79 }
80
81 } // namespace internal
82} // namespace mrs_lib
83
84
85#endif // MRS_LIB_CORO_TASK_IMPL_HPP_
All mrs_lib functions, classes, variables and definitions are contained in this namespace.
Definition attitude_converter.h:24