Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to continue a process after returning a response in a tide endpoint

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading