Asynchronous 延迟:优雅地取消.then()链?

Asynchronous 延迟:优雅地取消.then()链?,asynchronous,dojo,Asynchronous,Dojo,我有一个异步调用链,使用dojo.Deferred对象作为异步包装器(至少我是这么理解的)和.then()函数将异步调用“链接”在一起 在链中的任何一个链接上,某些测试可能会失败(例如,我的async store fetch没有返回任何对象,等等),我希望正常退出整个.then()链 这是我使用的链的形式。我如何在指定的位置杀死整个链条 asyncFunc(...).then( function(args) { //stuff... return myDeferredReturn

我有一个异步调用链,使用dojo.Deferred对象作为异步包装器(至少我是这么理解的)和.then()函数将异步调用“链接”在一起

在链中的任何一个链接上,某些测试可能会失败(例如,我的async store fetch没有返回任何对象,等等),我希望正常退出整个.then()链

这是我使用的链的形式。我如何在指定的位置杀死整个链条

asyncFunc(...).then( function(args) {
    //stuff...
    return myDeferredReturningFunction(args);
}).then( function(args2) {
    //do some test on args2
    //if test fails, **how to cancel the chain here?**
}).then( function(args3) { ... etc etc ...

注意:也许有人可以将其标记为“dojo.Deferred”?

抛出异常应该是一种简单的解救方法,因为它将跳出任何回调并跳入任何补充或后续的错误回调

快速示例:

dojo.xhrGet({url:'base.php'})
    .then(function() { console.log('foo'); throw 'argh!';})
    .then(function() { console.log('bar'); }); // bar never gets printed
更多信息:


我在Dojo 1.8中试过这个。如果then()上存在错误,则抛出不会取消链。将执行err回调。似乎没有办法在then链中真正抛出异常。此闭合缺陷似乎表明: