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

asyncify promisified functions #840

Merged
merged 12 commits into from
Jul 9, 2015
10 changes: 9 additions & 1 deletion lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -1186,10 +1186,18 @@
var result;
try {
result = func.apply(this, args);
// if result is Promise object
if (typeof result.then === "function") {
result.then(function(values) {
var args = [null].concat(values);
callback.apply(this, args);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There can be only one value from promise so can you do

callback.call(this, value)

}).catch(callback);
} else {
callback(null, result);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to have the callback call in the try/catch block.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep: The failing test is the one that guards against this: https://travis-ci.org/caolan/async/jobs/70115957

}
} catch (e) {
return callback(e);
}
callback(null, result);
});
};

Expand Down