gpt4 book ai didi

node.js - 有没有类似于 async.waterfall 的东西,但有错误?

转载 作者:太空宇宙 更新时间:2023-11-04 02:28:11 26 4
gpt4 key购买 nike

我有一个脚本,只有在前一个函数失败时才需要执行下一个函数。

有这样的事情吗?我不想链接所有函数,因为很难调试。

最佳答案

我在这种情况下使用的技巧是在回调的第一个参数中返回“done”:

async.waterfall([
function(callback){
if (doneWithWaterfall) {
return callback('done', 1); // optional 2nd argument
}
callback(null);
},
function(callback){
if (doneWithWaterfall) {
return callback('done', 2); // optional 2nd argument
}
callback(null);
}
], function(err, result) {
if (!err || err === 'done') {
console.log(result); // result is the 2nd argument of callback if returned
} else {
console.log(err);
}
});

关于node.js - 有没有类似于 async.waterfall 的东西,但有错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29084104/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com