bulldog2011/nano

Possible to operate synchronously ?

nobre84 opened this issue · 3 comments

Hi , is there any option or not so difficult way to implement blocking on the webservice result ? The usage scenario would be for web-services that are already asynchronous by design - i.e they return a Ticket that you poll periodically to verify the task is complete, and retrieve the result later. I'm having kind of a hard time handling state in countless callbacks.

Hi,

Pico is built on AFNetworking library which seems only supports asynchronous call, I am not sure if there is any simple way to do synchronous call on AFNetworking.

The raw NSURLConnection supports synchronous call, if possible, you may write your own synchronous web serivce library above NSURLConnection, you can leverage the serialization and deserialization part of Pico, the code logic is not complicated, hope you can make it.

Depends on how many user want such feature, I may add sync call in Pico in the future.

Thx!
-William

I have added a synchronous API to Nano (didn't do it for Pico yet).
Currently it may be used such as this, without requiring mwsc changes:
SOAPClient client = new SOAPClient();
client.setEndpointURL(...);
client.setSynchronous(true);
client.callSoapMethod(param, null); //do not supply a callback
Serializable result = client.getSynchronousResult(); //this will return the marshalled object received

It is imperative that this API is only used outside of the main application (UI) thread, or the app can become unresponsive (ANR), and ICS+ will raise NetworkOnMainThreadException.
Recommended usage: inside Android Service or AsyncTask

Thx for your work and feedback, can you submit a pull request, so I can integrate.

-William