3 Object.defineProperty(exports, "__esModule", {
7 exports.default = function (worker, concurrency) {
8 // Start with a normal queue
9 var q = (0, _queue2.default)(worker, concurrency);
11 // Override push to accept second parameter representing priority
12 q.push = function (data, priority, callback) {
13 if (callback == null) callback = _noop2.default;
14 if (typeof callback !== 'function') {
15 throw new Error('task callback must be a function');
18 if (!(0, _isArray2.default)(data)) {
21 if (data.length === 0) {
22 // call drain immediately if there are no tasks
23 return (0, _setImmediate2.default)(function () {
28 priority = priority || 0;
29 var nextNode = q._tasks.head;
30 while (nextNode && priority >= nextNode.priority) {
31 nextNode = nextNode.next;
34 for (var i = 0, l = data.length; i < l; i++) {
42 q._tasks.insertBefore(nextNode, item);
47 (0, _setImmediate2.default)(q.process);
50 // Remove unshift function
56 var _isArray = require('lodash/isArray');
58 var _isArray2 = _interopRequireDefault(_isArray);
60 var _noop = require('lodash/noop');
62 var _noop2 = _interopRequireDefault(_noop);
64 var _setImmediate = require('./setImmediate');
66 var _setImmediate2 = _interopRequireDefault(_setImmediate);
68 var _queue = require('./queue');
70 var _queue2 = _interopRequireDefault(_queue);
72 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
74 module.exports = exports['default'];
77 * The same as [async.queue]{@link module:ControlFlow.queue} only tasks are assigned a priority and
78 * completed in ascending priority order.
82 * @memberOf module:ControlFlow
84 * @see [async.queue]{@link module:ControlFlow.queue}
85 * @category Control Flow
86 * @param {Function} worker - An asynchronous function for processing a queued
87 * task, which must call its `callback(err)` argument when finished, with an
88 * optional `error` as an argument. If you want to handle errors from an
89 * individual task, pass a callback to `q.push()`. Invoked with
91 * @param {number} concurrency - An `integer` for determining how many `worker`
92 * functions should be run in parallel. If omitted, the concurrency defaults to
93 * `1`. If the concurrency is `0`, an error is thrown.
94 * @returns {module:ControlFlow.QueueObject} A priorityQueue object to manage the tasks. There are two
95 * differences between `queue` and `priorityQueue` objects:
96 * * `push(task, priority, [callback])` - `priority` should be a number. If an
97 * array of `tasks` is given, all tasks will be assigned the same priority.
98 * * The `unshift` method was removed.