-
Notifications
You must be signed in to change notification settings - Fork 44
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
If completer
rejects, callback is called twice
#51
Comments
Nice catch! It should probably be like this as to not swallow any errors thrown from the callback in the error path: result.then(
function (result) {
process.nextTick(function () { cb(null, result) })
},
function (err) {
process.nextTick(function () { cb(err) })
}
); |
Well, that means any exception from the callback will be turned into an uncaught exception. If instead you just do: result.then(
function (result) {cb(null, result);},
cb
); then the error gets propagated like any other error. Of course, the callback here is node.js code, so hopefully it's not going to throw random stuff at us. If it were me, I'd do: var pb = require('promise-breaker');
function wrapCompleter (completer) {
return function(line, cb) {pb.apply(completer, null, [line], cb;};
} Which covers the case where |
Yes, which I think is very important, since that is what happens when using other callback based apis.
But then it will be turned into an unhandled rejection instead? |
Oh, you're right. :) |
I was just browsing through the code and came across this:
So, if
result
rejects, we'll.catch(cb)
and call the callback, but then.then(function(result) {...
will be called with whatevercb
returns, so we'll callcb
again next tick. This should be:(Edit to add link to code)
The text was updated successfully, but these errors were encountered: