diff options
author | Caolan McMahon <caolan.mcmahon@gmail.com> | 2014-03-30 12:45:31 +0100 |
---|---|---|
committer | Caolan McMahon <caolan.mcmahon@gmail.com> | 2014-03-30 12:45:31 +0100 |
commit | f0040339e7978a74ecb248581c1f3ede18e02e45 (patch) | |
tree | 4567fab5283fe0eec60d50928fe8e63192413362 /lib | |
parent | 9d09fd13b3f87a1f094e7dfb249a02368d7ef948 (diff) | |
parent | 4722e785a4ebadba130be1a3d005703871b35233 (diff) | |
download | async-f0040339e7978a74ecb248581c1f3ede18e02e45.tar.gz |
Merge pull request #474 from maxkueng/pause-and-resume
queue.pause() and queue.resume()
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/async.js | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/async.js b/lib/async.js index 42b2621..e5e90fa 100755 --- a/lib/async.js +++ b/lib/async.js @@ -725,6 +725,7 @@ saturated: null, empty: null, drain: null, + paused: false, push: function (data, callback) { _insert(q, data, false, callback); }, @@ -732,7 +733,7 @@ _insert(q, data, true, callback); }, process: function () { - if (workers < q.concurrency && q.tasks.length) { + if (!q.paused && workers < q.concurrency && q.tasks.length) { var task = q.tasks.shift(); if (q.empty && q.tasks.length === 0) { q.empty(); @@ -760,6 +761,16 @@ }, idle: function() { return q.tasks.length + workers === 0; + }, + pause: function () { + if (q.paused === true) { return; } + q.paused = true; + q.process(); + }, + resume: function () { + if (q.paused === false) { return; } + q.paused = false; + q.process(); } }; return q; |