You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Would it be possible to have a when_any function, similar to when_all but it returns when the first awaitable is ready instead of waiting for all of them? Similar to Promise.race() in JS or select_all() in Rust.
The text was updated successfully, but these errors were encountered:
I had an issue for a long time considering adding it #153 , and I think its still a good idea. The trouble I ran into is that I'd probably need to introduce some type of cancellation token (or std::stop_token?) like behavior to every task. It would also be on the user to cancel the task if a stop was requested. So its possibly a large API change, or maybe it can be sorta shoe-horned in. But I haven't tried yet.
Wouldn't it just stop resuming the other tasks once one of them has finished? That would be fine for my use case at least. I'm not using the normal threading runtime though so I don't know if that's ok there...
You could return the tasks that didn't complete to the caller of when_any() so that it could resume them if it wants. Something like this (conceptually; obviously you don't want this actual API):
std::set<task<T>> tasks;
while (!tasks.empty()) {
std::set<task<T>> remaining_tasks;
task<T> completed_task;
T return_value = co_await when_all(tasks, &remaining_tasks);
tasks = remaining_tasks;
}
(Sorry if that's way off base; I'm a coroutine noob.)
Would it be possible to have a
when_any
function, similar towhen_all
but it returns when the first awaitable is ready instead of waiting for all of them? Similar toPromise.race()
in JS orselect_all()
in Rust.The text was updated successfully, but these errors were encountered: