YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
current_executor.hpp
Go to the documentation of this file.
1#pragma once
2
5
6namespace yaclib {
7namespace detail {
8
9template <bool Yield>
11 public:
12 constexpr bool await_ready() const noexcept {
13 return false;
14 }
15
16 template <typename Promise>
17 YACLIB_INLINE auto await_suspend(yaclib_std::coroutine_handle<Promise> handle) noexcept {
18 auto& promise = handle.promise();
19 _executor = promise._executor.Get();
20 YACLIB_ASSERT(_executor != nullptr);
21 if constexpr (Yield) {
22 _executor->Submit(promise);
23 } else {
24 return false;
25 }
26 }
27
28 [[nodiscard]] YACLIB_INLINE IExecutor& await_resume() const noexcept {
29 return *_executor;
30 }
31
32 private:
33 IExecutor* _executor = nullptr;
34};
35
36} // namespace detail
37
38/**
39 * Get current executor
40 */
44
45/**
46 * Instead of
47 * \code
48 * co_await yaclib::kYield;
49 * auto& executor = co_await yaclib::Current();
50 * \endcode
51 * or
52 * \code
53 * auto& executor = co_await yaclib::kCurrent;
54 * co_await On(executor);
55 * \endcode
56 * you can write
57 * auto& executor = co_await yaclib::Yield();
58 */
62
63} // namespace yaclib
YACLIB_INLINE auto await_suspend(yaclib_std::coroutine_handle< Promise > handle) noexcept
constexpr bool await_ready() const noexcept
YACLIB_INLINE IExecutor & await_resume() const noexcept
#define YACLIB_ASSERT(cond)
Definition log.hpp:85
YACLIB_INLINE detail::CurrentAwaiter< true > Yield() noexcept
Instead of.
YACLIB_INLINE detail::CurrentAwaiter< false > CurrentExecutor() noexcept
Get current executor.
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25