summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAydar Zartdinov <zartdinov@gmail.com>2015-07-09 06:05:43 +0300
committerAydar Zartdinov <zartdinov@gmail.com>2015-07-09 06:05:43 +0300
commit3c2fd71e350f6a5cda22696ed7cc2022fe566128 (patch)
treed43280c5a110839a212e2e6bd02b9573906317ba /lib
parentb89b1acf95188bc74e3e528a72bf22ce30e1b677 (diff)
downloadasync-3c2fd71e350f6a5cda22696ed7cc2022fe566128.tar.gz
callback moved out from try/catch block
unit tests for es6-promise and rsvp
Diffstat (limited to 'lib')
-rw-r--r--lib/async.js19
1 files changed, 10 insertions, 9 deletions
diff --git a/lib/async.js b/lib/async.js
index d9e6244..84d17aa 100644
--- a/lib/async.js
+++ b/lib/async.js
@@ -1186,18 +1186,19 @@
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);
- }).catch(callback);
- } else {
- callback(null, result);
- }
} catch (e) {
return callback(e);
}
+ // if result is Promise object
+ if (typeof result !== 'undefined' && typeof result.then === "function") {
+ result.then(function(value) {
+ callback(null, value);
+ }).catch(function(err) {
+ callback(new Error(err));
+ });
+ } else {
+ callback(null, result);
+ }
});
};