Haim
Posts: 0
Joined: Wed Sep 05, 2012 9:15 am

Are phonegap and parse call asynchronous

I have some strange behavior on my app due to what I think are asynchronous services that I'm not handling properly:

  1. I use a location service (via PhoneGap) that should return the device's lat/lng

  2. I have a parse REST API call that should return a collection of information that should be plotted as markers on a Google map.

    OK - when all conditions are just fine (e.g. reception, parse performance, etc) - then all seems ok - that is, I enter the mapping screen and everything is plotted correctly in the correct location (i.e. location worked quickly and smoothly and parse returned quickly and smoothly).

    Sometimes, the map is plotted in the wrong location (previous location instead of current location) - which tells me that the phone's current location might be an asynchronous call that I don't always catch without a callback.

    Also - sometimes I don't get any markers plotted which tells me that the return from parse was also missed without a callback.

    Do both of these require a callback? Example code for these? How would that work? I was relying on the "Success" event in Tiggzi - does that guarrentee that data was returned or that the call (potentially asynch) was return, but not yet finished.

    Details?

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Are phonegap and parse call asynchronous

When you say PhoneGap or Parse calls - these are actually JavaScript calls. For example, with Parse you are sending an Ajax request. To answer your questions, these requests are asynchronous. In other words, while one request is being executed, the next request can be sent.

Haim
Posts: 0
Joined: Wed Sep 05, 2012 9:15 am

Are phonegap and parse call asynchronous

Understood. Then can you suggest some place where I can find explicit documentation on proper callbacks or checks to this? For example, if I send a REST API call to parse to "GET" some information, how can I test that this information is actually ready? I thought (apparently mistakenly) that a "success event" meant that the service was really 100% finished.

How to test for a REST API status? What about the geolocation of the phone handset - how do I test that this is also finished?

Thanks.

Eric5020946
Posts: 0
Joined: Tue Sep 18, 2012 4:31 pm

Are phonegap and parse call asynchronous

read about standard ajax statuses

error - when http code returne (404 etc)
sucess - when 200, 304 and any output

completed when either error or success
it is confusing but I always check for success and check output against empty data array/json

it all depend on output and codes returned by your rest service

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Are phonegap and parse call asynchronous

Yes, these are the events that you can use.

Haim
Posts: 0
Joined: Wed Sep 05, 2012 9:15 am

Are phonegap and parse call asynchronous

Thanks - very helpful.

Haim
Posts: 0
Joined: Wed Sep 05, 2012 9:15 am

Are phonegap and parse call asynchronous

Thanks - I've followed your suggestions and I now see that on some devices, under some conditions - I'll timeout. Does anyone have a suggestion timeout value that isn't too lax?

I think that the standard one in Tiggzi is 5000 (msec) - so that's 5 seconds. I saw some posting somewhere that recommended 10 seconds (10000 msec). Is that too much. Anybody know the softspot?

Could there be some other reason? I've seen this timeout only on Android (so far)... when conditions (reception, standing outside, etc) are excellent, then I see no issues.

Suggestions?

Eric5020946
Posts: 0
Joined: Tue Sep 18, 2012 4:31 pm

Are phonegap and parse call asynchronous

5sec is very long time for http request to timeout... there is somethign wrong with your server or connection - check your http request in chrome in firebug/net or yslow, timeout happens if in 5 second you don;t get response from the server, I think that doesn't include time for data transfer once response is received

FYI if you build native app for app store, 10sec timeout will get your app rejected

Haim
Posts: 0
Joined: Wed Sep 05, 2012 9:15 am

Are phonegap and parse call asynchronous

Eric - thanks for the quick reply.

The request is a phonegap geolocation call. There's no server or browser issue that I'm aware of. When I run the app on a browser (emulating the handset inside of Tiggzi), I never see a timeout.

It's only on certain handsets.

OK - I agree that 5 secs ought to be enough... but this is really a function of the handset and phonegap (2.0.0 for Tiggzi, correct?)

Return to “Issues”