Skip to content

Commit b88f8d3

Browse files
wraveryRafał Hibner
authored and
Rafał Hibner
committed
fix(coro): stop spawning waiter threads for async futures
1 parent f310946 commit b88f8d3

File tree

1 file changed

+6
-53
lines changed

1 file changed

+6
-53
lines changed

include/graphqlservice/GraphQLService.h

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -342,40 +342,14 @@ class [[nodiscard]] AwaitableScalar
342342
std::promise<T> _promise;
343343
};
344344

345-
[[nodiscard]] bool await_ready() const noexcept
345+
[[nodiscard("unexpected call")]] constexpr bool await_ready() const noexcept
346346
{
347-
return std::visit(
348-
[](const auto& value) noexcept {
349-
using value_type = std::decay_t<decltype(value)>;
350-
351-
if constexpr (std::is_same_v<value_type, T>)
352-
{
353-
return true;
354-
}
355-
else if constexpr (std::is_same_v<value_type, std::future<T>>)
356-
{
357-
using namespace std::literals;
358-
359-
return value.wait_for(0s) != std::future_status::timeout;
360-
}
361-
else if constexpr (std::is_same_v<value_type,
362-
std::shared_ptr<const response::Value>>)
363-
{
364-
return true;
365-
}
366-
},
367-
_value);
347+
return true;
368348
}
369349

370350
void await_suspend(coro::coroutine_handle<> h) const
371351
{
372-
std::thread(
373-
[this](coro::coroutine_handle<> h) noexcept {
374-
std::get<std::future<T>>(_value).wait();
375-
h.resume();
376-
},
377-
std::move(h))
378-
.detach();
352+
h.resume();
379353
}
380354

381355
[[nodiscard]] T await_resume()
@@ -695,39 +669,18 @@ class [[nodiscard]] AwaitableObject
695669
std::promise<T> _promise;
696670
};
697671

698-
[[nodiscard]] bool await_ready() const noexcept
672+
[[nodiscard("unexpected call")]] constexpr bool await_ready() const noexcept
699673
{
700-
return std::visit(
701-
[](const auto& value) noexcept {
702-
using value_type = std::decay_t<decltype(value)>;
703-
704-
if constexpr (std::is_same_v<value_type, T>)
705-
{
706-
return true;
707-
}
708-
else if constexpr (std::is_same_v<value_type, std::future<T>>)
709-
{
710-
using namespace std::literals;
711-
712-
return value.wait_for(0s) != std::future_status::timeout;
713-
}
714-
},
715-
_value);
674+
return true;
716675
}
717676

718677
void await_suspend(coro::coroutine_handle<> h) const
719678
{
679+
<<<<<<< HEAD
720680
std::thread(
721681
[this](coro::coroutine_handle<> h) noexcept {
722682
std::get<std::future<T>>(_value).wait();
723-
h.resume();
724-
},
725-
std::move(h))
726-
.detach();
727-
}
728-
729683
[[nodiscard]] T await_resume()
730-
{
731684
return std::visit(
732685
[](auto&& value) -> T {
733686
using value_type = std::decay_t<decltype(value)>;

0 commit comments

Comments
 (0)