Corium 1.1.0
High-Performance Zero-Heap C++20 MPSC Application Runtime
Loading...
Searching...
No Matches
Delay.hpp
Go to the documentation of this file.
1
7#pragma once
8
9#include <chrono>
10#include <coroutine>
11#include <thread>
12
13namespace corium::async {
14
17 [[nodiscard]] constexpr bool await_ready() const noexcept { return false; }
18 void await_suspend(std::coroutine_handle<> handle) const noexcept {
19 handle.resume();
20 }
21 constexpr void await_resume() const noexcept {}
22};
23
25[[nodiscard]] inline constexpr YieldAwaiter yield() noexcept {
26 return YieldAwaiter{};
27}
28
30template <typename Rep, typename Period>
32 std::chrono::duration<Rep, Period> duration;
33
34 [[nodiscard]] constexpr bool await_ready() const noexcept {
35 return duration.count() <= 0;
36 }
37
38 void await_suspend(std::coroutine_handle<> handle) const {
39 std::this_thread::sleep_for(duration);
40 handle.resume();
41 }
42
43 constexpr void await_resume() const noexcept {}
44};
45
47template <typename Rep, typename Period>
48[[nodiscard]] inline auto delay(const std::chrono::duration<Rep, Period>& d) noexcept {
50}
51
52} // namespace corium::async
Definition AsyncEvent.hpp:14
constexpr YieldAwaiter yield() noexcept
Helper to yield execution in a coroutine.
Definition Delay.hpp:25
auto delay(const std::chrono::duration< Rep, Period > &d) noexcept
Helper to suspend coroutine for a given std::chrono duration.
Definition Delay.hpp:48
Awaitable that pauses the coroutine thread for the specified duration.
Definition Delay.hpp:31
std::chrono::duration< Rep, Period > duration
Definition Delay.hpp:32
constexpr bool await_ready() const noexcept
Definition Delay.hpp:34
constexpr void await_resume() const noexcept
Definition Delay.hpp:43
void await_suspend(std::coroutine_handle<> handle) const
Definition Delay.hpp:38
Awaitable that yields control back to the caller/event loop once.
Definition Delay.hpp:16
constexpr void await_resume() const noexcept
Definition Delay.hpp:21
void await_suspend(std::coroutine_handle<> handle) const noexcept
Definition Delay.hpp:18
constexpr bool await_ready() const noexcept
Definition Delay.hpp:17