Start a new topic

Offline / timeout

Still working out some of the fun parts in an app that mainly can work offline just as it does online.



Great that you can do an offline query (e.g. a search) against local storage..... right now, if the mobile device is online, I default to online. If offline, I default to offline... However sometimes (and not the fault of Kinvey at all), the mobile device THINKS it is online, when it is actually off (e.g. you have just walked out of wifi range, etc)



In that situation, I am trying to run the query online, when actually it should be offline against local storage. The online query doesn't reply because it is waiting on kinvey, but actually the internet connection isn't there, so the reply will never come.



WHAT I AM CURRENTLY DOING

Doing 2 queries (one online, one offline) and using logic to work out which one to show. Bit of a pain but at least conceptually OK. Makes the code a bit complex, especially as this is all happening concurrently.



WHAT I WOULD LIKE

To be able to set a timeout for an online query, and if not replied in e.g. 3 seconds, the library to automatically quit the request, and run the query offline instead.



Library: Angular




Hey A B, since this is for Angular I'm tagging with JS.
You can specify a timeout (in ms) when doing the request. When the request with times out, you can fire a local request instead:



```

var promise = $kinvey.DataStore.find(collection-name, null, { timeout: 3000 }).then(null, function(error) {

if(Kinvey.Error.REQUEST_TIMEOUT_ERROR === error.name) {// Timeout?

return $kinvey.DataStore.find(collection-name, null, { offline: true });

}

// Some other error occurred.

});

```
Thanks!



Re this timeout example - I couldn't see this in the docs anywhere..... is it worth you adding?
Thanks for your suggestion! The [list of errors](http://devcenter.kinvey.com/guides/troubleshooting) contains the timeout error, if more people struggle with this it is indeed worth adding a separate section on it.
Hi Mark

Re docs...... errors are fine. It was the ability to set a timeout (e.g. in your example to 3000 milliseconds) that I hadn't seen in the docs (Angular ones)
Login or Signup to post a comment