admin管理员组文章数量:1401628
I am using the node.js async package, specifically forEachSeries, to make a series of http requests based on parameters drawn from an array. In the callback of each request I have some if/else statements to respond to different types of responses.
// 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
}
}
Is there an equivalent to 'continue' that I can use inside of the else if above? This is not technically inside of a loop so continue does not work.
I am using the node.js async package, specifically forEachSeries, to make a series of http requests based on parameters drawn from an array. In the callback of each request I have some if/else statements to respond to different types of responses.
// 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
}
}
Is there an equivalent to 'continue' that I can use inside of the else if above? This is not technically inside of a loop so continue does not work.
Share Improve this question edited Feb 11, 2013 at 15:28 hippietrail 17k21 gold badges109 silver badges179 bronze badges asked Apr 11, 2012 at 13:15 TankofVinesTankofVines 1,1872 gold badges14 silver badges23 bronze badges 2-
There is a reason for you to don't have access to the
continue
statement inside a control structure likeif/else
. What exactly are you trying to do? 'Cause it looks to me like you need to review your logic... – Daniel Ribeiro Commented Apr 11, 2012 at 13:18 - The !response.results is most likely due to some rate limiting from the server. Currently, I can return the callback() on the forEachSeries that the request above is inside, but there is some potential data loss with this approach. Just trying to figure out if there is an equivalent to continue in a forEachSeries in node.js. Something similar to how return true is used in a jQuery $each. – TankofVines Commented Apr 11, 2012 at 13:29
1 Answer
Reset to default 6Since it is just a function you should be able to return
from it to have the same effect:
else if (!response.results) {
return;
}
本文标签:
版权声明:本文标题:javascript - Is there an equivalent statement to 'continue' when using node.js async forEachSeries? - Stack Over 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744250644a2597234.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论