lewissbaker / cppcoro

A library of C++ coroutine abstractions for the coroutines TS
MIT License
3.43k stars 472 forks source link

sync_wait does not support lambdas #149

Closed invexed closed 4 years ago

invexed commented 4 years ago
#include <cppcoro/sync_wait.hpp>
#include <cppcoro/task.hpp>

int main()
{
    return cppcoro::sync_wait([]() -> cppcoro::task<int> {
        co_return 0;
    });
}
error: no matching function for call to 'sync_wait'

    cppcoro::sync_wait([]() -> cppcoro::task<int> {

    ^~~~~~~~~~~~~~~~~~

.../include/cppcoro/sync_wait.hpp:18:7: note: candidate template ignored: substitution failure [with AWAITABLE = (lambda at <source>:6:24)]: no type named 'await_result_t' in 'cppcoro::awaitable_traits<(lambda at <source>:6:24) &&, void>'

        auto sync_wait(AWAITABLE&& awaitable)

             ^

1 error generated.

https://godbolt.org/z/-bMpCN

lewissbaker commented 4 years ago

You need to pass a task<> to sync_wait() not a function/lambda that returns a task<>.

Try immediately invoking the lamda and passing the result to sync_wait().

invexed commented 4 years ago

What a silly mistake. Thanks for pointing it out!