Async: Support question - read remaining number of tasks in async.queue

Created on 30 Sep 2017  路  6Comments  路  Source: caolan/async

I am using async.queue like so:

const q = async.queue((task, cb => task(cb));

How can I find out during debugging how many tasks remain on the queue (and maybe how many have completed?)?

I used util.inspect() to get the properties on the queue

 { _tasks: DLL { tail: null, head: null, length: 0 },
  concurrency: 3,
  payload: 1,
  saturated: [Function: noop],
  unsaturated: [Function: noop],
  buffer: 0.75,
  empty: [Function: noop],
  drain: [Function],
  error: [Function: noop],
  started: false,
  paused: false,
  push: [Function: push],
  kill: [Function: kill],
  unshift: [Function: unshift],
  remove: [Function: remove],
  process: [Function: process],
  length: [Function: length],
  running: [Function: running],
  workersList: [Function: workersList],
  idle: [Function: idle],
  pause: [Function: pause],
  resume: [Function: resume] }
question

Most helpful comment

q.length() will return the length of the queue. q._tasks.toArray() will give you a list of tasks in the queue. There's no way to tell how many have completed, unless you track that yourself.

To remove the drain callback:

q.drain = function () {}

No way to use multiple drain callbacks, but you can call multiple functions in the single drain callback.

All 6 comments

also, as an aside, curious about how to remove the drain callback, maybe like so?

q.drain = function(){
   q.drain = null; // this doesn't seem quite right?
};

also wondering if there is a way to use multiple drain callbacks.

thanks

q.length() will return the length of the queue. q._tasks.toArray() will give you a list of tasks in the queue. There's no way to tell how many have completed, unless you track that yourself.

To remove the drain callback:

q.drain = function () {}

No way to use multiple drain callbacks, but you can call multiple functions in the single drain callback.

@aearly thanks, got it, except:

q.length() will return the length of the queue. q._tasks.toArray()

what's the difference between those two? the length and the number of tasks? aren't they the same?

They are the same. Length of the queue = number of tasks in the queue.

got it, thank you...I think the docs could be improved here, how can we improve them with a PR?

Still don't know what the diff is between q.length() and q.running()

Was this page helpful?
0 / 5 - 0 ratings