[promise] fromNode helper
This commit is contained in:
parent
c3c662e2ae
commit
9a8ccc7e00
1 changed files with 9 additions and 0 deletions
|
@ -86,6 +86,15 @@ define(function (require) {
|
|||
|
||||
return Promise.resolve(value);
|
||||
};
|
||||
Promise.fromNode = function (takesCbFn) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
takesCbFn(function (err, ...results) {
|
||||
if (err) reject(err);
|
||||
else if (results.length > 1) resolve(results);
|
||||
else resolve(results[0]);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
return Promise;
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue