Skip to content

whilst should allow an asynchronous test function #156

Closed
@brianmaissy

Description

@brianmaissy

It would be useful (to me at least) if whilst could optionally accept an asynchronous test function. It would work by delegating to the normal whilst, just storing local state about the last outcome of the test. Something like this:

whilst: function(test, action, callback){
    if(test.length > 0) newWhilst(test, action, callback)
    else {
        ...
    }
},

newWhilst: function(test, action, callback){
    test(function(state){
       whilst(function(){
            return state;
        },
        function(callback){
            action(function(){
                test(function(result){
                    state = result;
                    callback();
                });
            });
        },
        callback);
    });
},

Is there a reason this feature isn't implemented? If not I'd be happy to add it and submit a pull request

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions