Skip to content
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

async.during iteratee callback do not support optional parameter #1217

Closed
thatisuday opened this issue Jul 4, 2016 · 9 comments
Closed

async.during iteratee callback do not support optional parameter #1217

thatisuday opened this issue Jul 4, 2016 · 9 comments
Milestone

Comments

@thatisuday
Copy link

I am using v2.0.0 on client side.

In async.during example, if we pass a optional value in callback of iterate, javascript show error of callback is not a function in truthy functon.

var count = 0;

async.during(
    function (callback) {
        console.warn(arguments);
        return callback(null, count < 5);
    },
    function (callback) {
        count++;
        setTimeout(function(){
          callback(null, count);
        }, 1000);
    },
    function (err, res) {
        console.info(res); // 5 seconds have passed
    }
);

Is there anything I am doing wrong? I guess this is also mentioned in documentation that callback will be passed an error and any arguments passed to the final fn's callback

@thatisuday
Copy link
Author

This does same with doDuring

@aearly
Copy link
Collaborator

aearly commented Jul 4, 2016

Which 2.0.0 RC version are you using?

@thatisuday
Copy link
Author

@aearly 6

@megawac
Copy link
Collaborator

megawac commented Jul 7, 2016

Any arguments you pass to callback will be passed to the predicate. Your code can be changed as follows,

var count = 0;

async.during(
    function (callback) {
        return arguments[arguments.length - 1](null, count < 5);
    },
    function (callback) {
        count++;
        setTimeout(function(){
          callback(null, count);
        }, 1000);
    },
    function (err) {
        // 5 seconds have passed
        console.log("done")
    }
);

This probably should be documented, if you're interested send a pull request

@megawac megawac added bug and removed bug labels Jul 7, 2016
@megawac
Copy link
Collaborator

megawac commented Jul 7, 2016

@aearly do we want to just remove optional parameters passed to during test functions? Doesn't seem so useful as async won't pass it in on the first call anyway (always undefined first run)

I'd vote scrap the extra args

@megawac megawac added this to the 2.0 milestone Jul 7, 2016
@aearly
Copy link
Collaborator

aearly commented Jul 8, 2016

whilst and until also have the same weird behavior where args from the async callback are only applied on the second test call. I think if you're using args from the fn's callback in the test, you're going to be using do(Whilst|Until|During) instead anyway. We should clarify the docs.

@megawac
Copy link
Collaborator

megawac commented Jul 8, 2016

I think we should just remove this behaviour

@aearly
Copy link
Collaborator

aearly commented Jul 8, 2016

Should we also remove the behavior for whilst and until? (e.g. not pass any args from the async fn's callback, whether its the first or later call of the test function?)

@megawac
Copy link
Collaborator

megawac commented Jul 8, 2016

I think so (never found it anything but weird) but I'd like to hear anyones
opinion that uses this functionality

On Fri, Jul 8, 2016 at 1:21 AM, Alex Early notifications@github.com wrote:

Should we also remove the behavior for whilst and until? (e.g. not pass
any args from the async fn's callback, whether its the first or later
call of the test function?)


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#1217 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/ADUIEF_4ISUEfbFly-OXKjcVXnFHL7yXks5qTd5WgaJpZM4JEQi1
.

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

No branches or pull requests

3 participants