Open zeroasterisk opened 10 years ago
FYI - here is my code and my failing unit test
Check the runAsync api: https://github.com/meteorhacks/meteor-async#asyncrunsyncfunction
On Thursday, October 2, 2014, alan blount notifications@github.com wrote:
I've read through the README, and this discovermeteor post https://www.discovermeteor.com/blog/wrapping-npm-packages/, and the wrapAsync http://docs.meteor.com/#meteor_wrapasync docs in Meteor core.
It works fine, when the "next" argument is the callback...
But take a look at this NPM method I'm trying to wrap:
https://github.com/moshen/node-googlemaps/blob/master/lib/googlemaps.js#L153
when I only pass in the origin and destination arguments, it works fine... when I do any others, it fails because the wrapAsync doesn't know where to pass in the callback.
Suggestions?
— Reply to this email directly or view it on GitHub https://github.com/meteorhacks/meteor-async/issues/1.
Arunoda Susiripala I curate Meteor Weekly - Check it out! http://meteorhacks.com/meteor-weekly/?utm_source=email-footer&utm_medium=email&utm_campaign=meteorweekly
You can also do something like this.
var wrappedFn = Meteor.wrapAsync(function (args, callback) {
// add callback at index 2
params.splice(2, 0, callback);
originalFunction.apply(this, args);
})
wrappedFn([origin, destination, sensor, ...], callback)
(I didn't test this code, just wrote it here on github)
@arunoda how about a third options argument to let users set the index of callback function? https://github.com/meteorhacks/meteor-async/blob/master/async.js#L31
Thanish solution works. But the third arg option is too much for a general purpose api.
Above api is having some bad design. So we don't need to optimize for that.
On Thursday, October 2, 2014, Muhammed Thanish notifications@github.com wrote:
@arunoda https://github.com/arunoda how about a third options argument to let users set the index of callback function? https://github.com/meteorhacks/meteor-async/blob/master/async.js#L31
— Reply to this email directly or view it on GitHub https://github.com/meteorhacks/meteor-async/issues/1#issuecomment-57577286 .
Arunoda Susiripala
@arunoda http://twitter.com/arunoda http://gplus.to/arunodahttps://github.com/arunoda http://www.linkedin.com/in/arunoda
I've read through the README, and this discovermeteor post, and the wrapAsync docs in Meteor core.
It works fine, when the "next" argument is the callback...
But take a look at this NPM method I'm trying to wrap: https://github.com/moshen/node-googlemaps/blob/master/lib/googlemaps.js#L153
when I only pass in the
origin
anddestination
arguments, it works fine... when I do any others, it fails because the wrapAsync doesn't know where to pass in the callback.Suggestions?