diff options
Diffstat (limited to 'lib/priorityQueue.js')
-rw-r--r-- | lib/priorityQueue.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/priorityQueue.js b/lib/priorityQueue.js index 90ca03e..a33f2f5 100644 --- a/lib/priorityQueue.js +++ b/lib/priorityQueue.js @@ -8,6 +8,29 @@ import setImmediate from './setImmediate'; import queue from './queue'; +/** + * The same as [`queue`](#queue) only tasks are assigned a priority and + * completed in ascending priority order. + * + * @name priorityQueue + * @static + * @memberOf async + * @see `async.queue` + * @category Control Flow + * @param {Function} worker - An asynchronous function for processing a queued + * task, which must call its `callback(err)` argument when finished, with an + * optional `error` as an argument. If you want to handle errors from an + * individual task, pass a callback to `q.push()`. Invoked with + * (task, callback). + * @param {number} concurrency - An `integer` for determining how many `worker` + * functions should be run in parallel. If omitted, the concurrency defaults to + * `1`. If the concurrency is `0`, an error is thrown. + * @returns {queue} A priorityQueue object to manage the tasks. There are two + * differences between `queue` and `priorityQueue` objects: + * * `push(task, priority, [callback])` - `priority` should be a number. If an + * array of `tasks` is given, all tasks will be assigned the same priority. + * * The `unshift` method was removed. + */ export default function(worker, concurrency) { function _compareTasks(a, b) { return a.priority - b.priority; |