Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[quick question] Why sync_wait a task returns a wrapped tuple? #1443

Open
lixin-wei opened this issue Dec 9, 2024 · 2 comments
Open

[quick question] Why sync_wait a task returns a wrapped tuple? #1443

lixin-wei opened this issue Dec 9, 2024 · 2 comments

Comments

@lixin-wei
Copy link

lixin-wei commented Dec 9, 2024

Hi I'm a novice to std::execution, I'm curious about the fowllowing example in this repo:

template <sender S1, sender S2>
exec::task<std::optional<int>> async_answer2(S1 s1, S2 s2) {
co_return co_await stopped_as_optional(async_answer(s1, s2));
}

auto [i] = stdexec::sync_wait(async_answer2(just(42), just())).value();

why sync_wait returns a std::tuple<std::optional<int>> instead of std::optional<int> directly?

It's a little unintutive, is it designed intentionally for some purpose?

@maikel
Copy link
Collaborator

maikel commented Dec 9, 2024

I think the answer is consistency. In the way it currently is, it is eaiser to use sync_wait in a generic context since it always returns a tuple. Note, that, in general, senders can complete with multiple values, whereas the exec::task has a single completion value type. Sync wait doesn't distinguish between single-value-senders and general senders and just transforms the result consistently.

@lixin-wei
Copy link
Author

get it, thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants