YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
yield.hpp
Go to the documentation of this file.
1#pragma once
2
5
6namespace yaclib {
7namespace detail {
8
9class [[nodiscard]] Yield final {
10 public:
11 constexpr bool await_ready() const noexcept {
12 return false;
13 }
14
15 template <typename Promise>
16 YACLIB_INLINE void await_suspend(yaclib_std::coroutine_handle<Promise> handle) const noexcept {
17 auto& promise = handle.promise();
18 YACLIB_ASSERT(promise._executor != nullptr);
19 promise._executor->Submit(promise);
20 }
21
22 constexpr void await_resume() const noexcept {
23 }
24};
25
26} // namespace detail
27
28/**
29 * Reschedule current job to it executor
30 * Useful for timeout checks, or if you job very big and doing only cpu not suspend work
31 */
32inline constexpr detail::Yield kYield;
33
34} // namespace yaclib
constexpr void await_resume() const noexcept
Definition yield.hpp:22
constexpr bool await_ready() const noexcept
Definition yield.hpp:11
YACLIB_INLINE void await_suspend(yaclib_std::coroutine_handle< Promise > handle) const noexcept
Definition yield.hpp:16
#define YACLIB_ASSERT(cond)
Definition log.hpp:85
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25
constexpr detail::Yield kYield
Reschedule current job to it executor Useful for timeout checks, or if you job very big and doing onl...
Definition yield.hpp:32