Anyone used NPM's async module in Meteor?

I like using caolan/async to control the flow of my program when using node. With Meteor 1.3’s NPM support, I am thinking about using it in my Meteor projects.

Has anyone used this in Meteor, and were there anything unexpected?

It should just work fine? Why don’t you give it a shot?

Yeah, it works fine. On the server side you need to use Meteor.bindEnvironment to bind the callbacks to the Fiber. This is needed when you want to use Meteor collections or Meteor.user() in the callback.

For server only code there is also the options Meteor.wrapAsync that converts asynchronous functions that take a callback to a synchronous style function.

Last but not least there are alternatives of handling asynchronous functions with Promises and the new async/await semantics of ES7 that build on top of Promises and will be available by default in Meteor 1.3.

2 Likes

For a good discussion of async/await in Meteor 1.3, see: Start using async/await instead of promises and callbacks