diff options
author | Craig Andrews <craig.andrews@bskyb.com> | 2013-09-10 13:36:15 +0100 |
---|---|---|
committer | Caolan McMahon <caolan@caolanmcmahon.com> | 2014-03-28 17:23:48 +0000 |
commit | e87eacd90327869880d8cc6f26ba300554d68720 (patch) | |
tree | e66113d66a1a60c3a0399ada529d315b0a073f6f | |
parent | 80c34f0b730965b103dca6429b0b6fa118c55437 (diff) | |
download | async-e87eacd90327869880d8cc6f26ba300554d68720.tar.gz |
Add idle() function to determine if the queue has any work
Documented idle() and running() functions.
-rw-r--r-- | README.md | 2 | ||||
-rwxr-xr-x | lib/async.js | 3 |
2 files changed, 5 insertions, 0 deletions
@@ -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; |