在我的代码中,基于特定条件,我想跳到该done函数,而不考虑所有then函数。
这个问题的原始版本在编辑中。以下是我正在处理的实际问题。带来不便敬请谅解
实际问题:
我正在读取一个文件并处理它。如果文件的内容符合某些条件,我必须对文件系统进行一系列操作(比如读写几个文件)然后执行done函数。如果条件不成立,我必须跳过所有一系列操作,我必须done直接执行函数。
我result在所有then函数中返回一个对象(可以说),然后在下一次then更新result并返回它。所以,当所有这些then都完成后,done就会有积累result。最后,done将处理result并打印它。
因此,如果最初不满足条件,done将简单地打印result(这将是空的)。
Q()
.then(readFile)
.then(function (contents) {
    var processResult = process the contents;
    if (processResult) {
        return {};
    } else {
        // How can I skip to `done` from here
    }
})
.then(function (results) {
    // do some more processing and update results
    return results;
})
...   // Few more then functions similar to the one above
...
.fail(function (exception) {
    console.error(exception.stack);
})
.done(function (results) {
   // do some more processing and update results
   console.log(results);
});