DPP icon indicating copy to clipboard operation
DPP copied to clipboard

when_all method

Open tarolling opened this issue 1 year ago • 6 comments

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.

tarolling avatar May 31 '24 20:05 tarolling

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 avatar May 31 '24 20:05 Mishura4

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.

Jaskowicz1 avatar Jun 09 '24 16:06 Jaskowicz1

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.

tarolling avatar Jun 09 '24 17:06 tarolling

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

Mishura4 avatar Jun 09 '24 17:06 Mishura4

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[bot] avatar Aug 09 '24 02:08 github-actions[bot]

Bump

Mishura4 avatar Aug 09 '24 03:08 Mishura4

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[bot] avatar Oct 09 '24 02:10 github-actions[bot]