1'use strict'; 2 3Object.defineProperty(exports, "__esModule", { 4 value: true 5}); 6 7exports.default = function (worker, concurrency) { 8 // Start with a normal queue 9 var q = (0, _queue2.default)(worker, concurrency); 10 11 var { 12 push, 13 pushAsync 14 } = q; 15 16 q._tasks = new _Heap2.default(); 17 q._createTaskItem = ({ data, priority }, callback) => { 18 return { 19 data, 20 priority, 21 callback 22 }; 23 }; 24 25 function createDataItems(tasks, priority) { 26 if (!Array.isArray(tasks)) { 27 return { data: tasks, priority }; 28 } 29 return tasks.map(data => { 30 return { data, priority }; 31 }); 32 } 33 34 // Override push to accept second parameter representing priority 35 q.push = function (data, priority = 0, callback) { 36 return push(createDataItems(data, priority), callback); 37 }; 38 39 q.pushAsync = function (data, priority = 0, callback) { 40 return pushAsync(createDataItems(data, priority), callback); 41 }; 42 43 // Remove unshift functions 44 delete q.unshift; 45 delete q.unshiftAsync; 46 47 return q; 48}; 49 50var _queue = require('./queue.js'); 51 52var _queue2 = _interopRequireDefault(_queue); 53 54var _Heap = require('./internal/Heap.js'); 55 56var _Heap2 = _interopRequireDefault(_Heap); 57 58function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 59 60module.exports = exports['default']; 61 62/** 63 * The same as [async.queue]{@link module:ControlFlow.queue} only tasks are assigned a priority and 64 * completed in ascending priority order. 65 * 66 * @name priorityQueue 67 * @static 68 * @memberOf module:ControlFlow 69 * @method 70 * @see [async.queue]{@link module:ControlFlow.queue} 71 * @category Control Flow 72 * @param {AsyncFunction} worker - An async function for processing a queued task. 73 * If you want to handle errors from an individual task, pass a callback to 74 * `q.push()`. 75 * Invoked with (task, callback). 76 * @param {number} concurrency - An `integer` for determining how many `worker` 77 * functions should be run in parallel. If omitted, the concurrency defaults to 78 * `1`. If the concurrency is `0`, an error is thrown. 79 * @returns {module:ControlFlow.QueueObject} A priorityQueue object to manage the tasks. There are three 80 * differences between `queue` and `priorityQueue` objects: 81 * * `push(task, priority, [callback])` - `priority` should be a number. If an 82 * array of `tasks` is given, all tasks will be assigned the same priority. 83 * * `pushAsync(task, priority, [callback])` - the same as `priorityQueue.push`, 84 * except this returns a promise that rejects if an error occurs. 85 * * The `unshift` and `unshiftAsync` methods were removed. 86 */