-
Notifications
You must be signed in to change notification settings - Fork 502
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
rayon::scope
in an async
context?
#1060
Comments
It's pretty fundamental to the lifetime of |
@cuviper If we ignore the existing implementation of Maybe an example would help. async {
let mut captured_data = 0;
// Hypothetical API
let fut = rayon::scoped_future(|| { captured_data = 1; return "done"; });
let message = fut.await;
} I think we just require that |
But this can't be guaranteed -- safe code can completely drop or forget the future, and then the borrow is lost while the scope/spawn is still using it. This is the same problem that the original |
Ah I see. That definitely throws a wrench into the mix. I'm not sure if what I'm asking for is possible. I found this discussion helpful as well: https://stackoverflow.com/questions/65269738/spawn-non-static-future-with-tokio |
This makes sense, but what is the idomatic way to bridge rayon with an async runtime with It seems there was a |
Answering my own question after a bit more research. There seems to be an incomplete attempt at adding this functionality in PR #679. Apart from this, there is also tokio-rayon and async-rayon. These crates are mostly the same with latter depending on the futures crates rather than the tokio crate. It is not complete support for async interop, but does provide an |
I want to be able to concurrently execute CPU-heavy tasks (on a
rayon
pool) and wait for IO futures (on ablocking
pool) that consume the results of the computational tasks. Because I'm in anasync
context, ideally I would be able tofutures::try_join!
those tasks. I've managed to wraprayon::spawn
in a future usingasync_channel
, but this is painful because I can only pass'static
data intorayon::spawn
. I'd rather use something likerayon::scope
, but this would necessarily block my async executor thread.I think I need some kind of
async fn
fromrayon
that would function likerayon::scope
but instead of blocking the thread, it returns a future that completes when the scoped threads complete.The text was updated successfully, but these errors were encountered: