Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

whilst should allow an asynchronous test function #156

Closed
brianmaissy opened this Issue · 7 comments

5 participants

@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

@brianmaissy

@caolan, just dug this up from a while ago. Thoughts?

@caolan
Owner

I can see that it might be useful, but we run into the backwards-incompatibility or the function arity confusion again. I think depending on function arity in this circumstance is less troublesome than the map/each/etc. iterators though.

Any ideas on how else we might implement this?

@brianmaissy

I agree that arity is not a huge issue here. What's the chances that someone would use a function that takes arguments as a predicate without giving it any?

But naming it differently is definitely not a bad idea, I like being safe. The first thing that comes to mind is whilstAsync, but it's a little awkward to suffix something in async with async. It could be confusing. We could clarify but make it slightly less pretty by calling it whilstAsyncCondition or whilstAsyncPredicate or something.

@caolan caolan closed this
@alizbazar
@lookfirst

I just noticed this issue was closed recently and I just ran into wanting this feature. Is there a workaround?

@aearly
Collaborator
@lookfirst

Nevermind, I just ended up using forever and a workaround there instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.