Skip to content

Another take on adding abort functionality - #5

Open
ozkozk wants to merge 1 commit into
TomFrost:masterfrom
ozkozk:patch-1
Open

ozkozk wants to merge 1 commit into
TomFrost:masterfrom
ozkozk:patch-1

Conversation

@ozkozk

@ozkozk ozkozk commented Apr 3, 2015

Copy link
Copy Markdown

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.

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.
@ozkozk

ozkozk commented Apr 3, 2015

Copy link
Copy Markdown
Author

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>
    }
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant