|
1512 | 1512 | res(args);
|
1513 | 1513 | }
|
1514 | 1514 |
|
1515 |
| - var item = { |
| 1515 | + var item = q._createTaskItem( |
1516 | 1516 | data,
|
1517 |
| - callback: rejectOnError ? |
1518 |
| - promiseCallback : |
| 1517 | + rejectOnError ? promiseCallback : |
1519 | 1518 | (callback || promiseCallback)
|
1520 |
| - }; |
| 1519 | + ); |
1521 | 1520 |
|
1522 | 1521 | if (insertAtFront) {
|
1523 | 1522 | q._tasks.unshift(item);
|
|
1599 | 1598 | var isProcessing = false;
|
1600 | 1599 | var q = {
|
1601 | 1600 | _tasks: new DLL(),
|
| 1601 | + _createTaskItem (data, callback) { |
| 1602 | + return { |
| 1603 | + data, |
| 1604 | + callback |
| 1605 | + }; |
| 1606 | + }, |
1602 | 1607 | *[Symbol.iterator] () {
|
1603 | 1608 | yield* q._tasks[Symbol.iterator]();
|
1604 | 1609 | },
|
|
2348 | 2353 | * Result will be the first item in the array that passes the truth test
|
2349 | 2354 | * (iteratee) or the value `undefined` if none passed. Invoked with
|
2350 | 2355 | * (err, result).
|
2351 |
| - * @returns A Promise, if no callback is passed |
| 2356 | + * @returns {Promise} a promise, if a callback is omitted |
2352 | 2357 | * @example
|
2353 | 2358 | *
|
2354 | 2359 | * // dir1 is a directory that contains file1.txt, file2.txt
|
|
2420 | 2425 | * Result will be the first item in the array that passes the truth test
|
2421 | 2426 | * (iteratee) or the value `undefined` if none passed. Invoked with
|
2422 | 2427 | * (err, result).
|
2423 |
| - * @returns a Promise if no callback is passed |
| 2428 | + * @returns {Promise} a promise, if a callback is omitted |
2424 | 2429 | */
|
2425 | 2430 | function detectLimit(coll, limit, iteratee, callback) {
|
2426 | 2431 | return _createTester(bool => bool, (res, item) => item)(eachOfLimit(limit), coll, iteratee, callback)
|
|
2446 | 2451 | * Result will be the first item in the array that passes the truth test
|
2447 | 2452 | * (iteratee) or the value `undefined` if none passed. Invoked with
|
2448 | 2453 | * (err, result).
|
2449 |
| - * @returns a Promise if no callback is passed |
| 2454 | + * @returns {Promise} a promise, if a callback is omitted |
2450 | 2455 | */
|
2451 | 2456 | function detectSeries(coll, iteratee, callback) {
|
2452 | 2457 | return _createTester(bool => bool, (res, item) => item)(eachOfLimit(1), coll, iteratee, callback)
|
|
3662 | 3667 |
|
3663 | 3668 | var nextTick = wrap(_defer$1);
|
3664 | 3669 |
|
3665 |
| - var _parallel = awaitify((eachfn, tasks, callback) => { |
| 3670 | + var parallel = awaitify((eachfn, tasks, callback) => { |
3666 | 3671 | var results = isArrayLike(tasks) ? [] : {};
|
3667 | 3672 |
|
3668 | 3673 | eachfn(tasks, (task, key, taskCb) => {
|
|
3835 | 3840 | * }
|
3836 | 3841 | *
|
3837 | 3842 | */
|
3838 |
| - function parallel(tasks, callback) { |
3839 |
| - return _parallel(eachOf$1, tasks, callback); |
| 3843 | + function parallel$1(tasks, callback) { |
| 3844 | + return parallel(eachOf$1, tasks, callback); |
3840 | 3845 | }
|
3841 | 3846 |
|
3842 | 3847 | /**
|
|
3860 | 3865 | * @returns {Promise} a promise, if a callback is not passed
|
3861 | 3866 | */
|
3862 | 3867 | function parallelLimit(tasks, limit, callback) {
|
3863 |
| - return _parallel(eachOfLimit(limit), tasks, callback); |
| 3868 | + return parallel(eachOfLimit(limit), tasks, callback); |
3864 | 3869 | }
|
3865 | 3870 |
|
3866 | 3871 | /**
|
|
4144 | 4149 | * @param {number} concurrency - An `integer` for determining how many `worker`
|
4145 | 4150 | * functions should be run in parallel. If omitted, the concurrency defaults to
|
4146 | 4151 | * `1`. If the concurrency is `0`, an error is thrown.
|
4147 |
| - * @returns {module:ControlFlow.QueueObject} A priorityQueue object to manage the tasks. There are two |
| 4152 | + * @returns {module:ControlFlow.QueueObject} A priorityQueue object to manage the tasks. There are three |
4148 | 4153 | * differences between `queue` and `priorityQueue` objects:
|
4149 | 4154 | * * `push(task, priority, [callback])` - `priority` should be a number. If an
|
4150 | 4155 | * array of `tasks` is given, all tasks will be assigned the same priority.
|
4151 |
| - * * The `unshift` method was removed. |
| 4156 | + * * `pushAsync(task, priority, [callback])` - the same as `priorityQueue.push`, |
| 4157 | + * except this returns a promise that rejects if an error occurs. |
| 4158 | + * * The `unshift` and `unshiftAsync` methods were removed. |
4152 | 4159 | */
|
4153 | 4160 | function priorityQueue(worker, concurrency) {
|
4154 | 4161 | // Start with a normal queue
|
4155 | 4162 | var q = queue$1(worker, concurrency);
|
4156 |
| - var processingScheduled = false; |
| 4163 | + |
| 4164 | + var { |
| 4165 | + push, |
| 4166 | + pushAsync |
| 4167 | + } = q; |
4157 | 4168 |
|
4158 | 4169 | q._tasks = new Heap();
|
| 4170 | + q._createTaskItem = ({data, priority}, callback) => { |
| 4171 | + return { |
| 4172 | + data, |
| 4173 | + priority, |
| 4174 | + callback |
| 4175 | + }; |
| 4176 | + }; |
4159 | 4177 |
|
4160 |
| - // Override push to accept second parameter representing priority |
4161 |
| - q.push = function(data, priority = 0, callback = () => {}) { |
4162 |
| - if (typeof callback !== 'function') { |
4163 |
| - throw new Error('task callback must be a function'); |
| 4178 | + function createDataItems(tasks, priority) { |
| 4179 | + if (!Array.isArray(tasks)) { |
| 4180 | + return {data: tasks, priority}; |
4164 | 4181 | }
|
4165 |
| - q.started = true; |
4166 |
| - if (!Array.isArray(data)) { |
4167 |
| - data = [data]; |
4168 |
| - } |
4169 |
| - if (data.length === 0 && q.idle()) { |
4170 |
| - // call drain immediately if there are no tasks |
4171 |
| - return setImmediate$1(() => q.drain()); |
4172 |
| - } |
4173 |
| - |
4174 |
| - for (var i = 0, l = data.length; i < l; i++) { |
4175 |
| - var item = { |
4176 |
| - data: data[i], |
4177 |
| - priority, |
4178 |
| - callback |
4179 |
| - }; |
| 4182 | + return tasks.map(data => { return {data, priority}; }); |
| 4183 | + } |
4180 | 4184 |
|
4181 |
| - q._tasks.push(item); |
4182 |
| - } |
| 4185 | + // Override push to accept second parameter representing priority |
| 4186 | + q.push = function(data, priority = 0, callback) { |
| 4187 | + return push(createDataItems(data, priority), callback); |
| 4188 | + }; |
4183 | 4189 |
|
4184 |
| - if (!processingScheduled) { |
4185 |
| - processingScheduled = true; |
4186 |
| - setImmediate$1(() => { |
4187 |
| - processingScheduled = false; |
4188 |
| - q.process(); |
4189 |
| - }); |
4190 |
| - } |
| 4190 | + q.pushAsync = function(data, priority = 0, callback) { |
| 4191 | + return pushAsync(createDataItems(data, priority), callback); |
4191 | 4192 | };
|
4192 | 4193 |
|
4193 |
| - // Remove unshift function |
| 4194 | + // Remove unshift functions |
4194 | 4195 | delete q.unshift;
|
| 4196 | + delete q.unshiftAsync; |
4195 | 4197 |
|
4196 | 4198 | return q;
|
4197 | 4199 | }
|
|
4212 | 4214 | * @param {Function} callback - A callback to run once any of the functions have
|
4213 | 4215 | * completed. This function gets an error or result from the first function that
|
4214 | 4216 | * completed. Invoked with (err, result).
|
4215 |
| - * @returns undefined |
| 4217 | + * @returns {Promise} a promise, if a callback is omitted |
4216 | 4218 | * @example
|
4217 | 4219 | *
|
4218 | 4220 | * async.race([
|
|
4905 | 4907 | *
|
4906 | 4908 | */
|
4907 | 4909 | function series(tasks, callback) {
|
4908 |
| - return _parallel(eachOfSeries$1, tasks, callback); |
| 4910 | + return parallel(eachOfSeries$1, tasks, callback); |
4909 | 4911 | }
|
4910 | 4912 |
|
4911 | 4913 | /**
|
|
5737 | 5739 | * @param {Function} [callback] - An optional callback to run once all the
|
5738 | 5740 | * functions have completed. This will be passed the results of the last task's
|
5739 | 5741 | * callback. Invoked with (err, [results]).
|
5740 |
| - * @returns undefined |
| 5742 | + * @returns {Promise} a promise, if a callback is omitted |
5741 | 5743 | * @example
|
5742 | 5744 | *
|
5743 | 5745 | * async.waterfall([
|
|
5885 | 5887 | mapValuesSeries,
|
5886 | 5888 | memoize,
|
5887 | 5889 | nextTick,
|
5888 |
| - parallel, |
| 5890 | + parallel: parallel$1, |
5889 | 5891 | parallelLimit,
|
5890 | 5892 | priorityQueue,
|
5891 | 5893 | queue: queue$1,
|
|
5993 | 5995 | exports.mapValuesSeries = mapValuesSeries;
|
5994 | 5996 | exports.memoize = memoize;
|
5995 | 5997 | exports.nextTick = nextTick;
|
5996 |
| - exports.parallel = parallel; |
| 5998 | + exports.parallel = parallel$1; |
5997 | 5999 | exports.parallelLimit = parallelLimit;
|
5998 | 6000 | exports.priorityQueue = priorityQueue;
|
5999 | 6001 | exports.queue = queue$1;
|
|
0 commit comments