Async: question: check an async.queue to see if a matching task has already been inserted?

Created on 27 Jul 2017  ·  3Comments  ·  Source: caolan/async

Is there anyway to look at the tasks of a current queue to determine if the task you are about to put in might already match a task currently in the queue?

enhancement queue

Most helpful comment

Although, as an enhancement to the queue, we could expose a q[Symbol.iterator] property for exposing an implementation-agnostic way to iterate the current items of the queue.

All 3 comments

There is no officially sanctioned way to iterate the queue. There is a q._tasks property that exposes the underlying linked list for the queue. You can either iterate the linked list, or call q._tasks.toArray().find(...) to see if your task already exists.

This is an implementation detail, so it is not documented. It might break in the future if we change how the queue works internally.

Although, as an enhancement to the queue, we could expose a q[Symbol.iterator] property for exposing an implementation-agnostic way to iterate the current items of the queue.

I would also like this feature, many other queues have this feature.
q.contains(task) would be very useful!

Was this page helpful?
0 / 5 - 0 ratings