Another take on adding abort functionality
I find the node-attempt module pretty useful, however as noted by someone else, the abort functionality is very much needed since sometimes further retries are either not necessary, or in my case, since I'm communicating with an external physical device, can be harmful (causing the other device to get stuck). The proposed solution tries to adhere to the way the existing code is written by adding another optional function that can be set by the caller to attempt. This function is being called every time before the main function (tryFunc) is being called. If the abort function returns true, no more attempts will be made and the callback will be issued immediately with a specific error to indicate the abort.
Let me know what you think about this :)
btw, I tested it in my environment and it works just fine.
To add clarification on this proposal, here's how it will be used:
attempt(
{
retries: 2,
interval: 1000,
onError: function (error) {
console.log("Error occurred: " + error);
},
abort: function () {
if (<condition>)
return true;
else
return false;
}
},
function () {
someShadyFunction(this);
},
function (error) {
<do something here>
}
);