summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Andrews <craig.andrews@bskyb.com>2013-09-10 13:36:15 +0100
committerCaolan McMahon <caolan@caolanmcmahon.com>2014-03-28 17:23:48 +0000
commite87eacd90327869880d8cc6f26ba300554d68720 (patch)
treee66113d66a1a60c3a0399ada529d315b0a073f6f
parent80c34f0b730965b103dca6429b0b6fa118c55437 (diff)
downloadasync-e87eacd90327869880d8cc6f26ba300554d68720.tar.gz
Add idle() function to determine if the queue has any work
Documented idle() and running() functions.
-rw-r--r--README.md2
-rwxr-xr-xlib/async.js3
2 files changed, 5 insertions, 0 deletions
diff --git a/README.md b/README.md
index a60ca4d..acee1b2 100644
--- a/README.md
+++ b/README.md
@@ -1075,6 +1075,8 @@ The `queue` object returned by this function has the following properties and
methods:
* `length()` - a function returning the number of items waiting to be processed.
+* `running()` - a function returning the number of items currently being processed.
+* `idle()` - a function returning false if there are items waiting or being processed, or true if not.
* `concurrency` - an integer for determining how many `worker` functions should be
run in parallel. This property can be changed after a `queue` is created to
alter the concurrency on-the-fly.
diff --git a/lib/async.js b/lib/async.js
index 312e645..2313bb1 100755
--- a/lib/async.js
+++ b/lib/async.js
@@ -755,6 +755,9 @@
},
running: function () {
return workers;
+ },
+ idle: function() {
+ return q.tasks.length == 0 && workers == 0;
}
};
return q;