ground-db
ground-db copied to clipboard
How to get offline method callback?
consider this example:
Meteor.call 'doSomething', (err, suc) =>
if err
console.log 'error!'
else
console.log 'succes!'
When online this works fine. But when offline, there's never a callback. How to get success from Ground for a method call?
events in ground db is poorly documented - but you can do Ground.on('method', function(evt) {});: https://github.com/GroundMeteor/db/blob/connection-driver/groundDB.client.js#L728
Thanks for your quick response. However this event only seems to be emitted after the connection becoming online again.
I need a callback while being offline.
so you want a callback when you do the method call? Meteor.call returns the callback when the server has responded.
I understand.
But my code is waiting for a callback to continue, so it breaks the code.
With Ground, when offline, method calls are being saved to be resumed later. So there's no callback -obviously - from server. But it would be great if Ground gives a callback instead that the method is successfully saved (perhaps via an event).
For example, if you're method is called 'doSomething' add an event handler:
Ground.on 'doSomething', (status) ->
console.log status
# status = saved / not saved
got it
@satyavh I know it's not the best solution but currently for this case I am using caolan/async - here's an example: I want to update 2 records from different Collections and have the callbacks running even in offline mode, I do somethinig like this.
async.parallel [
(callback) ->
a = Collection.update
_id: some._id
,
$set:
value: "some value"
, (error) ->
callback(error, "Collection")
# even if offline
if a and !Meteor.status().connected then callback(null, "Collection")
(callback) ->
b = Collection2.update
_id: some._id
,
$set:
value: "some other value"
, (error) ->
callback(error, "Collection")
# even if offline
if b and !Meteor.status().connected then callback(null, "Collection2")
], (err, results) ->
if err
console.log err.message
else
# success
# do something when both are successfull :)
Hope this helps.
Todor
Hello tagrudev, what's the meteor package for this?