Permalink
Browse files

Add clearQueue function.

  • Loading branch information...
1 parent 175bd24 commit f3e8cfa241a485806a80fc9f2511880bb6cd3075 @jaredhanson committed Jan 14, 2012
Showing with 14 additions and 0 deletions.
  1. +10 −0 lib/functionpool/pool.js
  2. +4 −0 test/pool-test.js
View
@@ -107,6 +107,16 @@ Pool.prototype.task = function() {
}
/**
+ * Remove all queued tasks from the pool.
+ *
+ * @api public
+ */
+Pool.prototype.clearQueue = function() {
+ var len = this._queue.length;
+ this._queue.splice(0, len);
+}
+
+/**
* Dispatch next task to an available worker.
*
* @api private
View
@@ -34,6 +34,10 @@ vows.describe('Pool').addBatch({
assert.isFalse(pool.task());
assert.equal(pool._queue.length, 2);
},
+ 'should have no items in queue after clearing': function (pool) {
+ pool.clearQueue();
+ assert.equal(pool._queue.length, 0);
+ },
},
'pool with specific size option': {

0 comments on commit f3e8cfa

Please sign in to comment.