Open arvsr1988 opened 6 years ago
Shouldn't be enough to send request to callback_url in long_running_task (at the end)?
the code runs synchronously because the future
@meshula what do you mean by somewhere else?
I also tried std::thread().detch() but the thread only executes after the application stops.
Can you paste code snippet?
What I mean is that the variable named task is scoped to the body of the lambda function, and it's destructor will block at the end of the lambda function execution. If you want the future to not block, it's scope has to be outside of the lambda function. For example, if it exists at the scope of main, it won't block until main finishes.
small correction. std::thread::detach() does what I want but I'm concerned about the thread management as each request will spawn a new thread. Will crow framework manage the lifecycle of the threads that are detached or will I have to manage it myself?
"Detaches the thread represented by the object from the calling thread, allowing them to execute independently from each other.
Both threads continue without blocking nor synchronizing in any way. Note that when either one ends execution, its resources are released.
After a call to this function, the thread object becomes non-joinable and can be destroyed safely."
(http://www.cplusplus.com/reference/thread/thread/detach/)
So it looks like you just create thread object, detach it and forget about it ;) It should return resources as soon as it ends it task.
I have a route where i want to send a 200 response, run a function and then send a request to a callback url. I'm trying to use std::async to achieve this but the code appears to run synchronously. Here's my code.
how can i do what i intend to do?