Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix bug where idle is emitted too often with a single worker.

  • Loading branch information...
commit 175bd244e846b122c5a40d9577c579924f5657f6 1 parent b9b011c
@jaredhanson authored
Showing with 25 additions and 2 deletions.
  1. +1 −1  lib/functionpool/pool.js
  2. +24 −1 test/pool-test.js
View
2  lib/functionpool/pool.js
@@ -58,7 +58,7 @@ function Pool(options, fn) {
this.on('done', function() {
// TODO: emit a `drain` event if the pool was previously queuing, and now
// has slots available
- if (self._working == 0) { self.emit('idle'); }
+ if (self._working == 0 && self._queue.length == 0) { self.emit('idle'); }
if (self._queue.length == 0) { return; }
self._dispatch();
})
View
25 test/pool-test.js
@@ -60,7 +60,30 @@ vows.describe('Pool').addBatch({
},
},
- 'pool that works and then idles': {
+ 'pool with single worker that works and then idles': {
+ topic: function() {
+ var self = this;
+ var count = 0;
+ var pool = new Pool({ size: 1 }, function(done) {
+ count++;
+ setTimeout(done, 100);
+ });
+ pool.on('idle', function() {
+ self.callback(null, pool, count);
+ });
+ pool.task();
+ pool.task();
+ pool.task();
+ pool.task();
+ pool.task();
+ },
+
+ 'should work 5 times': function (err, pool, count) {
+ assert.equal(count, 5);
+ },
+ },
+
+ 'pool with multiple workers that works and then idles': {
topic: function() {
var self = this;
var count = 0;
Please sign in to comment.
Something went wrong with that request. Please try again.