aboutsummaryrefslogtreecommitdiffstats
path: root/library
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2024-08-02 11:46:37 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2024-08-02 11:57:04 +0300
commit92b85f69f24f17bdfe07ce6b79a1c89a6be6570b (patch)
tree42d3b0bb7e24ea104ff996e4e0c7bd53e6b79805 /library
parent5a45964796c9ec3473a077d84d58554fa74d6582 (diff)
downloadydb-92b85f69f24f17bdfe07ce6b79a1c89a6be6570b.tar.gz
Intermediate changes
Diffstat (limited to 'library')
-rw-r--r--library/cpp/threading/future/core/coroutine_traits.h62
1 files changed, 33 insertions, 29 deletions
diff --git a/library/cpp/threading/future/core/coroutine_traits.h b/library/cpp/threading/future/core/coroutine_traits.h
index 5871e22a35..f032190fb1 100644
--- a/library/cpp/threading/future/core/coroutine_traits.h
+++ b/library/cpp/threading/future/core/coroutine_traits.h
@@ -51,42 +51,46 @@ struct std::coroutine_traits<NThreading::TFuture<T>, Args...> {
};
};
-template<typename T>
-struct TFutureAwaitable {
- NThreading::TFuture<T> Future;
+namespace NThreading {
- TFutureAwaitable(NThreading::TFuture<T> future)
- : Future{future}
- {
- }
+ template<typename T>
+ struct TFutureAwaitable {
+ NThreading::TFuture<T> Future;
- bool await_ready() const noexcept {
- return Future.HasValue() || Future.HasException();
- }
+ TFutureAwaitable(NThreading::TFuture<T> future) noexcept
+ : Future{std::move(future)}
+ {
+ }
- void await_suspend(auto h) noexcept {
- /*
- * This library assumes that resume never throws an exception.
- * This assumption is made due to the fact that the users of these library in most cases do not need to write their own coroutine handlers,
- * and all coroutine handlers provided by the library do not throw exception from resume.
- *
- * WARNING: do not change subscribe to apply or something other here, creating an extra future state degrades performance.
- */
- Future.NoexceptSubscribe(
- [h](auto) mutable noexcept {
- h();
- }
- );
- }
+ bool await_ready() const noexcept {
+ return Future.IsReady();
+ }
- decltype(auto) await_resume() {
- return Future.GetValue();
- }
-};
+ void await_suspend(auto h) noexcept {
+ /*
+ * This library assumes that resume never throws an exception.
+ * This assumption is made due to the fact that the users of these library in most cases do not need to write their own coroutine handlers,
+ * and all coroutine handlers provided by the library do not throw exception from resume.
+ *
+ * WARNING: do not change subscribe to apply or something other here, creating an extra future state degrades performance.
+ */
+ Future.NoexceptSubscribe(
+ [h](auto) mutable noexcept {
+ h();
+ }
+ );
+ }
+
+ decltype(auto) await_resume() {
+ return Future.GetValue();
+ }
+ };
+
+} // namespace NThreading
template<typename T>
auto operator co_await(const NThreading::TFuture<T>& future) {
- return TFutureAwaitable{future};
+ return NThreading::TFutureAwaitable{future};
}
namespace NThreading {