You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the Web spider version 3 code example (Asynchronous Control Flow Patterns with Callbacks) chapter, The author defined a done callback (will be called asynchronously by the spiderLinks function).
function done (err) {
if (err) {
hasErrors = true
return cb(err)
}
if (++completed === links.length && !hasErrors) {
return cb()
}
}
The author mentioned that:
The hasErrors variable is necessary because if one parallel task
fails, we want to immediately call the callback with the given error.
Also, we need to make sure that other parallel tasks that might still
be running won't invoke the callback again.
I read done definition multiple times, and think that the !hasErrors check is not need in the ++completed === links.length && !hasErrors) because if we have at least one error (in one of the concurrent functions) ++completed will not be reached in that function, so the completed === links.length will never be satisfied. so probably we need to check !hasErrors in: