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
Promise then() only supports a single argument #3
Comments
Unfortunately, this is a Promise thing. If you try:
It'll print out The "easy" fix to this is, instead of calling One thing I thought about doing when I wrote this was to check the arguments count in the callback, and then return arguments verbatim if I was calling another callback, or else automagically gather them up into an array like this if there was more than one of them when calling into This would be a pretty easy thing to do here. (And you don't even have to worry about fixing it in If this is a fix that works for you, I'll whip up a PR, get you to try it out, and then I'll push it as 3.0? |
Ah, darn, I was afraid of that. Thanks for the explanation and quick reply. Oh wow, sure, that sounds great! Just so I understand, you're saying that the classic callback case would not change, and continue to work as it does now, returning N inline arguments. But the promise resolve would return an array of arguments if and only if more than 1 was passed? |
Yeah, exactly. I'd want to make it a major number change, just in case anyone is accidentally passing more arguments than they're supposed to today. :) But the whole point of promise-breaker is supposed to be to make it easy to convert existing libraries to use Promises, so I definitely want a solution that doesn't change how an existing callback function works. |
Perfect, that sounds totally awesome. Yeah, I have an existing API that I'm trying to promiseify, which returns multiple arguments for some of its methods. Totally understood on the major version bump. Thanks again -- I look forward to testing v3 out! |
Ok. There's a PR here: (There's a few other minor changes in master, too, because I added eslint and fixed all the things it found. Shouldn't be any behavior changes from this, though, so I just pushed that straight to master before cutting this branch.) If you could please have a read through the README.md changes and make sure they make sense, and try this out and make sure it works for you, that would be awesome. :) |
PR looks good to me. The only thing I would change is perhaps the wording in the docs:
I am wondering if this will trip anyone up, because technically only the 2nd argument onward is going into the array. The first argument is of course the "error" and isn't included in the promise resolve. Perhaps this wording would be a bit clearer: if Not sure if that is an improvement, but no big deal. Your code example makes it perfectly clear what is going on anyway. The PR is golden, sir! |
I like it. I made another minor change after re-reading it, too. Published as v3.0.0. |
Works perfectly, thank you so much! |
Hello there! This is an awesome module, and is exactly what I am looking for. I just have one question. When using the callback syntax, I can pass multiple variables after the 1st error argument, and they all show up in the callback function, like this:
In the above example, val1 is
Hello
, and val2 isWorld
. This is exactly what I expect. Console output:But when I use the same exact setup but call myFunc using a promise pattern, I get an undefined for the 2nd argument:
Console output:
Am I doing something wrong here?
Thanks!
The text was updated successfully, but these errors were encountered: