使用节点时是否有等效的语句“继续”.js 为每个系列异步

Is there an equivalent statement to 'continue' when using node.js async forEachSeries?

本文关键字:继续 js 异步 个系列 语句 节点 是否      更新时间:2023-09-26

>我正在使用node.js异步包,特别是EachSeries,根据从数组中提取的参数发出一系列http请求。在每个请求的回调中,我有一些 if/else 语句来响应不同类型的响应。

// This is the callback of a GET request inside of a forEachSeries
function(error, response) {
    if (response.results) {
        // Do something with results
    }
    else if (!response.results) {
        // Would like to use a continue statement here, but
        // this is not inside of a loop
    }
    else {
        // Do something else
    }
}

如果有等效的"继续",我可以在上面使用吗?从技术上讲,这不是在循环内部,因此 continue 不起作用。

由于它只是一个函数,您应该能够从中return以获得相同的效果:

else if (!response.results) {
    return;
}