我想知道以下是否是正常行为?
代码
var when = require('when'); // I'm using when@3.7.4 node_modules/when
console.log("INIT");
when.promise(function(resolve, reject) {
return when.reject("false")
.then(function(ok) {
console.log("Step 1 - in then, ok = %s", ok);
return 'ok1';
}, function(err) {
console.log("Step 1.1 - in catch, err = %s", err);
return reject(err);
}).then(function(ok) {
console.log("Step 2 - in then, ok2 = %s", ok);
return resolve("done");
}).catch(function(err) {
console.log("Step 3 - in catch, err = %s", err);
return reject(err);
});
}).then(function(mainok) {
console.log("Step 9 - in main then, mainok = %s", mainok);
}).catch(function(err) {
console.log("Step 9 - in main catch, err = %s", err);
});
这是我运行时收到的输出
INIT
Step 1.1 - in catch, err = false
Step 2 - in then, ok2 = undefined
Step 9 - in main catch, err = false
阅读 API,我期望会调用第 1.1 步,然后调用第 9 步而不是第 2 步。
这是一个错误还是我误读了 API?
感谢您的提示!