In my Meteor client code, I am trying to use a third-party API that only has asynchronous calls. How can I use Meteor.wrapAsync on the client to call this API in a synchronous style? The docs show that this is possible: http://docs.meteor.com/#/full/meteor_wrapasync
Here is a sample code that I would like to call in a synchronous style:
var func1 = function(callback) { Meteor.setTimeout(function() { console.log('func1 executing'); callback(null, {success: true}); }, 2000); }; var func2 = function(callback) { Meteor.setTimeout(function() { console.log('func2 executing'); callback(null, {success: true}); }, 1000); }; var wrapped1 = Meteor.wrapAsync(func1); var wrapped2 = Meteor.wrapAsync(func2); Template.test.rendered = function() { wrapped1(); console.log('After wrapped1()'); wrapped2(); console.log('After wrapped2()'); };
This currently produces this conclusion:
After wrapped1() After wrapped2() func2 executing func1 executing
I would like it to produce:
func1 executing After wrapped1() func2 executing After wrapped2()
I put this code in MeteorPad here: http://meteorpad.com/pad/fLn9DXHf7XAACd9gq/Leaderboard
source share