Meteor call resulting in Collection.insert: how to make this run synchronously? -


i know how make meteor methods run synchronously via either meteor.wrapasynch , creating new future() on server.

however, i'm having problem when call on method via meteor.call("mymethod") insert or delete document. collection.insert supposed synchronous nature, on application, seems run asynchronously because there times when entire document doesn't insert db before iron router takes me next page.

here how code looks on client (took of out because it's irrelevant):

template.mytemplate.events({   "submit .legitform": function(e){      e.preventdefault();      meteor.call("deletedata");     });  // file manipulation in space.        async.each(array, processingfxn, function(error) {          flattened = _.flatten(results);          meteor.call("insertcollect", flattened);       }); 

on server, methods generic collection.insert , remove:

  meteor.methods({     insertcoll: function(document){       var currentuser = meteor.userid();       bank.insert({userid: currentuser, data: document});      },     deletedata: function(){       bank.remove({userid: this.userid});     }   }); 

ideally want first delete call finish before going on file manipulation part, etc, etc. tried passing callbacks in collection.insert , remove methods, doesn't work because guess turns insert , remove methods asynchronous.

the meteor docs says if callback provided used, otherwise method called synchronously 'if possible'.

to insure order should use callback there:

    template.mytemplate.events({       "submit .legitform": function(e){          e.preventdefault();          meteor.call("deletedata", function(result) {           // file manipulation in space.           async.each(array, processingfxn, function(error) {             flattened = _.flatten(results);             meteor.call("insertcollect", flattened);         });     }); }); 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -