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

when_all method #1153

Open
tarolling opened this issue May 31, 2024 · 6 comments
Open

when_all method #1153

tarolling opened this issue May 31, 2024 · 6 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers part fixed Issue is partially fixed

Comments

@tarolling
Copy link
Contributor

Is your feature request related to a problem? Please describe.
No problems, just inspiration from the implemented when_any with coroutines.

Describe the solution you'd like
Stated above, it would be nice to have a when_all (analogous to a Promise.allSettled from JS) method that works very similarly to when_any, except on the return condition. So all coroutines in the proposed when_all call would have to be fulfilled before resuming execution. In other words, it would resume when all coroutines complete.

Describe alternatives you've considered
Instead of alternatives, I'll give a use case. Say you want to send a DM to multiple users and want to wait until all of them have responded/interacted/etc. with the message. You could use this when_all to do this very easily.

Additional context
This may already be a feature idk, but if not, it would be a logical pairing with when_any.

@Mishura4
Copy link
Member

Mishura4 commented May 31, 2024

Thanks for the suggestion! I've been putting this off mostly because it's very easy to do it without a dedicated library feature:

dpp::task<void> tasks[4];

for (auto& task : tasks) {
  task = bot.co_do_something();
}
for (auto& task : tasks) {
  co_await task;
}

Though maybe a when_all could do something this can't, I'm not sure. It could also just exist and do that, I just haven't had much time lately so it's been low priority.

@Mishura4 Mishura4 self-assigned this May 31, 2024
@Mishura4 Mishura4 added enhancement New feature or request good first issue Good for newcomers part fixed Issue is partially fixed labels May 31, 2024
@Jaskowicz1
Copy link
Contributor

Jaskowicz1 commented Jun 9, 2024

Thanks for the suggestion! I've been putting this off mostly because it's very easy to do it without a dedicated library feature:

dpp::task<void> tasks[4];

for (auto& task : tasks) {
  task = bot.co_do_something();
}
for (auto& task : tasks) {
  co_await task;
}

Though maybe a when_all could do something this can't, I'm not sure. It could also just exist and do that, I just haven't had much time lately so it's been low priority.

Tbh I would take a when_all as a "fire in any order and be await them all to complete", but I guess you could just let them fire in order.

I do wonder if there's any specific case to needing it to be randomly fired.

@tarolling
Copy link
Contributor Author

Could jobs be launched in parallel perhaps? I'm not sure if when_any is implemented like this, or if this is feasible. Would be something interesting to explore if it's possible though.

@Mishura4
Copy link
Member

Mishura4 commented Jun 9, 2024

Could jobs be launched in parallel perhaps? I'm not sure if when_any is implemented like this, or if this is feasible. Would be something interesting to explore if it's possible though.

This happens to begin with with dpp::task and dpp::async

Copy link
Contributor

github-actions bot commented Aug 9, 2024

This issue has had no activity and is being marked as stale. If you still wish to continue with this issue please comment to reopen it.

@github-actions github-actions bot added the Stale label Aug 9, 2024
@Mishura4
Copy link
Member

Mishura4 commented Aug 9, 2024

Bump

@Jaskowicz1 Jaskowicz1 removed the Stale label Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers part fixed Issue is partially fixed
Projects
None yet
Development

No branches or pull requests

3 participants