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

Reader().map() fails to limit properly the number of parallel instances of a function. #126

Open
slawo opened this issue Nov 28, 2014 · 3 comments
Labels

Comments

@slawo
Copy link

slawo commented Nov 28, 2014

When setting the limit to 1 the given function is executed twice in parallel:

Test case:

  var Q = require('q');
  var Reader = require("q-io/reader");
  var data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
  var count = 0;
  var func = function(d) {
    var deferred = Q.defer();
    console.log("+ d", d, "count:", ++count)
    setTimeout(function() {
      console.log("-d", d, "count:", --count);
      deferred.resolve(d);
    }, 200);
    return deferred.promise;
  }
  var runOnAll = new Reader(data).map(func, null, 1).all();

The resulting output:

+ d 1 count: 1
+ d 2 count: 2
-d 1 count: 1
-d 2 count: 0
+ d 3 count: 1
+ d 4 count: 2
-d 3 count: 1
-d 4 count: 0
+ d 5 count: 1
+ d 6 count: 2
-d 5 count: 1
-d 6 count: 0
+ d 7 count: 1
+ d 8 count: 2
-d 7 count: 1
-d 8 count: 0
+ d 9 count: 1
+ d 10 count: 2
-d 9 count: 1
-d 10 count: 0

q: 1.1.2
q-io: 2.0.6

@slawo
Copy link
Author

slawo commented Nov 28, 2014

Unless my understanding of the function .map(func, null, 1) is wrong the resulting behavior should be only one instance of func being executed at a time.

Tried with q: 2.0.2 to the same result.

@kriskowal
Copy link
Owner

Thank you!

@hthetiot
Copy link
Collaborator

Could be related to collections, we removed it

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

No branches or pull requests

3 participants