New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dowhilst does not test on error in cb #1287
Comments
I just read the docs closer and saw Any tip on how to achieve what i'm trying to do (test the error and maybe retry)? |
I had the idea to capture the outcome from the microservice call and just return the error as a "result" and test |
This is a pattern to hack around the behavior, but it breaks the typical async pattern: var myservice = require('myservice');
async.doWhilst(
function(cb_dw) {
// Call the service, "catch" the error and pass it to the test function
return myservice.something("do it", function(err, result) {
if (err) {
return cb_dw(null, err);
} else {
return cb_dw(null, result);
});
}, function(result) {
// Test function determines if result is actually a retriable error,
// say a network communication issue
if (result instanceof NetworkError) {
return true;
}
return false;
}, function(err, result) {
if (result instanceof Error) {
err = result;
result = undefined;
}
}
); |
I just ran into the same(?) issue in async.whilst(). the documentation states:
from that documentation I did not realize that calling the I also would like the whilst() function to behave as documented, meaning that I am allowed to call the |
I think we should keep it as is (and perhaps make the docs more clear).
var count = 0;
var result, err;
try {
do {
result = (function (){
switch (count) {
case 0 :
return "Yes0";
case 1 :
throw new Error("Both");
case 2 :
throw new Error("Just An Error");
default:
throw new Error("Didnt expect this to be called");
}
})();
} while(test(result));
} catch (e) {
err = e;
}
console.log("FINALLY", err, result);
function test(results) {
console.log("Tester", err, results, count++);
return true;
} You wouldn't expect For the kind of control flow you want, there are several options. We have |
It depends of the module version you are using it version 2.6 is a function , 3.1 is asyncFunc From 2.6
*From 3.1
|
Version: 2.0.1
Env: Node v6.2.1
Reproduce code:
Output, with comments:
Expected: if the cb_dw receives an error it should continue to call the test function until test function returns false.
Actual: doWhilst calls the final callback as soon as cb_dw receives an error.
Longer explanation:
I am trying to do a retry that tests the error and will retry depending on the error received. So for example I may call out to a service and will retry if the error is a network style error (socket connection timeout for example) , but do not want to retry if its an authentication err (eg microservice returns InvalidCredentials error if failed auth) . If I use retry It will retry w/ bad credentials N times. So I'my trying to use doWhilst to ensure I run it atleast once, and give up if Credential Errors, but retry if network errors.
The text was updated successfully, but these errors were encountered: