-
Notifications
You must be signed in to change notification settings - Fork 509
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
Blocking in spawn_future_async
's argument?
#311
Comments
Hmm, that seems surprising. I would not expect |
Looking at your example, my guess is that the problem actually has to do with cancellation, and not true blocking. In particular, if the "slow" future happens to be cancelled before it has actually started, you will be ok. But once it starts, it won't be asynchronously interrupted, and hence it will run to completion. But I'm not sure then why the "working example" doesn't encounter a problem. I'll try to give this a spin locally (I guess that test case is standalone? looks that way.) |
Yes, the test case is standalone (modulo Cargo.toml). |
As for why I expected it to work: my expectation was that |
This code was removed in #716. |
The documentation for
spawn_future_async
says that the future it's passed is run in rayon's thread pool, and the returned future polls for the result. I had assumed that means that the intended use is to do number crunching/blocking operations inside the passed future, and polling the returnedRayonFuture
(e.g. in a tokio reactor) wouldn't block.This is inconsistent with experimentation. Distilled example: https://github.com/aweinstock314/power/blob/master/examples/rayon_test.rs, full context of what I was trying to do: https://github.com/aweinstock314/power/blob/354921a2b37d5c28d9ec02e26746d1f9e6e4632a/src/main.rs#L200-L234
The workaround of combining
rayon::spawn_async
andfutures::sync::oneshot::channel
has the semantics that I hoped to get fromspawn_future_async
. I'm not sure if this is a documentation bug or an implementation bug.The text was updated successfully, but these errors were encountered: