|
6 | 6 |
|
7 | 7 | #include <algorithm> |
8 | 8 | #include <chrono> |
| 9 | +#include <concepts> |
9 | 10 | #include <cstdint> |
10 | 11 | #include <functional> |
11 | 12 | #include <optional> |
@@ -73,7 +74,8 @@ auto wait(int64_t fork_id, duration_type timeout) noexcept -> kphp::coro::task<s |
73 | 74 | auto& fork_instance_st{ForkInstanceState::get()}; |
74 | 75 | auto opt_info{fork_instance_st.get_info(fork_id)}; |
75 | 76 | if (!opt_info || !(*opt_info).get().opt_handle || (*opt_info).get().awaited) [[unlikely]] { |
76 | | - kphp::log::warning("fork does not exist or has already been awaited by another fork: id -> {}", fork_id); |
| 77 | + // TODO: uncomment this warning after we stabilize K2 |
| 78 | + // kphp::log::warning("fork does not exist or has already been awaited by another fork: id -> {}", fork_id); |
77 | 79 | co_return std::nullopt; |
78 | 80 | } |
79 | 81 |
|
@@ -122,18 +124,29 @@ auto wait(int64_t fork_id, duration_type timeout) noexcept -> kphp::coro::task<s |
122 | 124 |
|
123 | 125 | } // namespace kphp::forks |
124 | 126 |
|
125 | | -template<typename T> |
126 | | -requires(is_optional<T>::value || std::same_as<T, mixed> || is_class_instance<T>::value) |
127 | | -kphp::coro::task<T> f$wait(int64_t fork_id, double timeout = -1.0) noexcept { |
128 | | - auto opt_result{co_await kphp::forks::id_managed( |
129 | | - kphp::forks::wait<T>(fork_id, std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::duration<double>{timeout})))}; |
130 | | - co_return opt_result ? T{*std::move(opt_result)} : T{}; |
| 127 | +template<std::default_initializable return_type> |
| 128 | +requires(is_optional<return_type>::value || std::same_as<return_type, mixed> || is_class_instance<return_type>::value) |
| 129 | +kphp::coro::task<return_type> f$wait(int64_t fork_id, double timeout = -1.0) noexcept { |
| 130 | + auto opt_result{co_await kphp::forks::id_managed(kphp::forks::wait<return_type>(fork_id, std::chrono::duration<double>{timeout}))}; |
| 131 | + co_return opt_result ? return_type{*std::move(opt_result)} : return_type{}; |
131 | 132 | } |
132 | 133 |
|
133 | | -template<typename T> |
134 | | -requires(is_optional<T>::value || std::same_as<T, mixed> || is_class_instance<T>::value) |
135 | | -kphp::coro::task<T> f$wait(Optional<int64_t> opt_fork_id, double timeout = -1.0) noexcept { |
136 | | - co_return co_await f$wait<T>(opt_fork_id.has_value() ? opt_fork_id.val() : kphp::forks::INVALID_ID, timeout); |
| 134 | +template<typename return_type> |
| 135 | +requires(is_optional<return_type>::value || std::same_as<return_type, mixed> || is_class_instance<return_type>::value) |
| 136 | +kphp::coro::task<return_type> f$wait(Optional<int64_t> opt_fork_id, double timeout = -1.0) noexcept { |
| 137 | + co_return co_await f$wait<return_type>(opt_fork_id.has_value() ? opt_fork_id.val() : kphp::forks::INVALID_ID, timeout); |
| 138 | +} |
| 139 | + |
| 140 | +template<typename return_type> |
| 141 | +requires(is_optional<return_type>::value || std::same_as<return_type, mixed> || is_class_instance<return_type>::value) |
| 142 | +kphp::coro::task<return_type> f$wait_synchronously(int64_t fork_id) noexcept { |
| 143 | + co_return co_await f$wait<return_type>(fork_id); |
| 144 | +} |
| 145 | + |
| 146 | +template<typename return_type> |
| 147 | +requires(is_optional<return_type>::value || std::same_as<return_type, mixed> || is_class_instance<return_type>::value) |
| 148 | +kphp::coro::task<return_type> f$wait_synchronously(Optional<int64_t> opt_fork_id) noexcept { |
| 149 | + co_return co_await f$wait<return_type>(opt_fork_id); |
137 | 150 | } |
138 | 151 |
|
139 | 152 | // ================================================================================================ |
|
0 commit comments