Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there any way to use this when the callback isn't the last argument? #1

Open
zeroasterisk opened this issue Oct 2, 2014 · 5 comments

Comments

@zeroasterisk
Copy link

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 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?

@zeroasterisk
Copy link
Author

FYI - here is my code and my failing unit test

@arunoda
Copy link
Member

arunoda commented Oct 2, 2014

Check the runAsync api:
https://github.com/meteorhacks/meteor-async#asyncrunsyncfunction

On Thursday, October 2, 2014, alan blount [email protected] 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
#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

@thani-sh
Copy link

thani-sh commented Oct 2, 2014

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)

@thani-sh
Copy link

thani-sh commented Oct 2, 2014

@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

@arunoda
Copy link
Member

arunoda commented Oct 2, 2014

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 [email protected]
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
#1 (comment)
.


Arunoda Susiripala

@arunoda http://twitter.com/arunoda
http://gplus.to/arunodahttps://github.com/arunoda
http://www.linkedin.com/in/arunoda

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants