Is it possible to send a response from an endpoint and then continue running ?(in the background) So when the endpoint gets called the caller gets some response but the server continues doing things :
app.at("/endpoint").post(myendpoint);
async fn myendpoint(mut req: Request<State>) -> tide::Result {
let body= Body::from_json(some_json).unwrap();
Ok(body.into()) //continue doing stuff after this (calling another function)
}
>Solution :
You can spawn a thread. Even after you process your request and return the response, the thread will continue doing what it needs to do for as long as needed.
An example:
use std::thread;
let hnd = thread::spawn(|| {
// Put your thread code here
});
That’s a regular thread, no async stuff. Generally, if you expect hundreds or thousands of concurrent calls, you might consider another, more-scalable approach.
Read more on thread spawning here.