Replies: 1 comment 3 replies
-
Rocket 0.5 is built on async Rust and will handle this quite gracefully. You probably want to spawn a tokio task for the long running process and then await that. tokio will run that task on its pool of threads and the rest of the Rocket process will continue handling requests. Something like this: use rocket::tokio;
#[get("/something")]
async fn your_handler() -> YourResponseType {
let res = tokio::task::spawn_blocking(move || {
// long running stuff in here
})
.await;
// Generate response using result of long running task
} |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The service I'm building processes data on the server and takes long time (3mins) to finish and return a result.
What's best way to handle such cases?
Maybe return, do processing, and call some callback?
Is it possible to do such thing with Rocket?
Beta Was this translation helpful? Give feedback.
All reactions