-
Notifications
You must be signed in to change notification settings - Fork 95
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
Call to rest api breaks after first successful call #96
Comments
Don't call CloseWhenReady() here. Call it in the main() function if you need to prevent it from exiting the application before the rest operations are done. |
Hello, I tried you solution, but if I move CloseWhenReady() in main function at the end, then the list is always empty after the call to GetImages method. Then I tried in another way. I don't need the function to be asynchronous, because I need to wait the call to GetImages before doing other things and moving ahead in the code.
and
Is my understanding correct ? Is this using only the main current thread and not creating another thread ? |
CloseWhenReady is used to tell the library to finish whatever it is doing and then quit. It can be used to hold the main thread off until the requests finish. But if you have more work, don't call it at all. If you have more work, just make sure that the main thread don't exit the main() function, or use the main thread to handle the IO. Don't call CloseWhenReady() until you have finished all your requests. |
Ok I understand. I would like to go synchronous for my needs, is the last code I posted the right way ? It doesn't seem ok to me because I don't have a way to wait for the lambda to be executed if I remove CloseWhenReady call, so the list of images is always empty... Sorry for so many question but maybe now I'm near to the solution |
The point with asynchronous programming is not to wait. You get the result inside the lambda, and while the request is pending, your threads are free to do away with other work. If you /really/ want to wait on the outside, you can use a std::future for that. |
Sometimes it is a good choice to do synchronous requests, depending on the overall architecture of the system... |
This is an interesting question actually: do I have to protect the RestClient object with a mutex when I call ProcessWithPromise()? |
Hello,
first of all thanks for your beautiful library.
I have the following problem, maybe I'm doing something wrong but I don't understand what...
This is my code, very simple and taken from one of the tutorials.
I create at startup the client in this way: I register my url and then create client.
Then I start calling a Rest API (which is tested from other not c++ clients and has no working problems) which returns a list of objects, Image objects in this case.
This is the method that I call several times in a loop with different "vid" parameter passed to the function:
I understand that this is calling the lambda in a co-routine managed by boost library.
The first call always works good giving back the correct list of images.
Then if I try another call in the loop, the lambda is never called again...
If I destroy the client object before every call everything works good.
Did I miss something ? What's wrong in my code ?
Thank You, your work is much appreciated.
Best Regards
Alessandro
The text was updated successfully, but these errors were encountered: