root / HServer / 00.Server / 00.Program / node_modules / async / queue.js
이력 | 보기 | 이력해설 | 다운로드 (5.21 KB)
| 1 | 39 | HKM | 'use strict';
|
|---|---|---|---|
| 2 | |||
| 3 | Object.defineProperty(exports, "__esModule", {
|
||
| 4 | value: true |
||
| 5 | }); |
||
| 6 | |||
| 7 | exports.default = function (worker, concurrency) { |
||
| 8 | return (0, _queue2.default)(function (items, cb) { |
||
| 9 | worker(items[0], cb);
|
||
| 10 | }, concurrency, 1);
|
||
| 11 | }; |
||
| 12 | |||
| 13 | var _queue = require('./internal/queue'); |
||
| 14 | |||
| 15 | var _queue2 = _interopRequireDefault(_queue);
|
||
| 16 | |||
| 17 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
||
| 18 | |||
| 19 | module.exports = exports['default'];
|
||
| 20 | |||
| 21 | /**
|
||
| 22 | * A queue of tasks for the worker function to complete.
|
||
| 23 | * @typedef {Object} QueueObject
|
||
| 24 | * @memberOf module:ControlFlow
|
||
| 25 | * @property {Function} length - a function returning the number of items
|
||
| 26 | * waiting to be processed. Invoke with `queue.length()`.
|
||
| 27 | * @property {boolean} started - a boolean indicating whether or not any
|
||
| 28 | * items have been pushed and processed by the queue.
|
||
| 29 | * @property {Function} running - a function returning the number of items
|
||
| 30 | * currently being processed. Invoke with `queue.running()`.
|
||
| 31 | * @property {Function} workersList - a function returning the array of items
|
||
| 32 | * currently being processed. Invoke with `queue.workersList()`.
|
||
| 33 | * @property {Function} idle - a function returning false if there are items
|
||
| 34 | * waiting or being processed, or true if not. Invoke with `queue.idle()`.
|
||
| 35 | * @property {number} concurrency - an integer for determining how many `worker`
|
||
| 36 | * functions should be run in parallel. This property can be changed after a
|
||
| 37 | * `queue` is created to alter the concurrency on-the-fly.
|
||
| 38 | * @property {Function} push - add a new task to the `queue`. Calls `callback`
|
||
| 39 | * once the `worker` has finished processing the task. Instead of a single task,
|
||
| 40 | * a `tasks` array can be submitted. The respective callback is used for every
|
||
| 41 | * task in the list. Invoke with `queue.push(task, [callback])`,
|
||
| 42 | * @property {Function} unshift - add a new task to the front of the `queue`.
|
||
| 43 | * Invoke with `queue.unshift(task, [callback])`.
|
||
| 44 | * @property {Function} saturated - a callback that is called when the number of
|
||
| 45 | * running workers hits the `concurrency` limit, and further tasks will be
|
||
| 46 | * queued.
|
||
| 47 | * @property {Function} unsaturated - a callback that is called when the number
|
||
| 48 | * of running workers is less than the `concurrency` & `buffer` limits, and
|
||
| 49 | * further tasks will not be queued.
|
||
| 50 | * @property {number} buffer - A minimum threshold buffer in order to say that
|
||
| 51 | * the `queue` is `unsaturated`.
|
||
| 52 | * @property {Function} empty - a callback that is called when the last item
|
||
| 53 | * from the `queue` is given to a `worker`.
|
||
| 54 | * @property {Function} drain - a callback that is called when the last item
|
||
| 55 | * from the `queue` has returned from the `worker`.
|
||
| 56 | * @property {Function} error - a callback that is called when a task errors.
|
||
| 57 | * Has the signature `function(error, task)`.
|
||
| 58 | * @property {boolean} paused - a boolean for determining whether the queue is
|
||
| 59 | * in a paused state.
|
||
| 60 | * @property {Function} pause - a function that pauses the processing of tasks
|
||
| 61 | * until `resume()` is called. Invoke with `queue.pause()`.
|
||
| 62 | * @property {Function} resume - a function that resumes the processing of
|
||
| 63 | * queued tasks when the queue is paused. Invoke with `queue.resume()`.
|
||
| 64 | * @property {Function} kill - a function that removes the `drain` callback and
|
||
| 65 | * empties remaining tasks from the queue forcing it to go idle. Invoke with `queue.kill()`.
|
||
| 66 | */
|
||
| 67 | |||
| 68 | /**
|
||
| 69 | * Creates a `queue` object with the specified `concurrency`. Tasks added to the
|
||
| 70 | * `queue` are processed in parallel (up to the `concurrency` limit). If all
|
||
| 71 | * `worker`s are in progress, the task is queued until one becomes available.
|
||
| 72 | * Once a `worker` completes a `task`, that `task`'s callback is called.
|
||
| 73 | *
|
||
| 74 | * @name queue
|
||
| 75 | * @static
|
||
| 76 | * @memberOf module:ControlFlow
|
||
| 77 | * @method
|
||
| 78 | * @category Control Flow
|
||
| 79 | * @param {Function} worker - An asynchronous function for processing a queued
|
||
| 80 | * task, which must call its `callback(err)` argument when finished, with an
|
||
| 81 | * optional `error` as an argument. If you want to handle errors from an
|
||
| 82 | * individual task, pass a callback to `q.push()`. Invoked with
|
||
| 83 | * (task, callback).
|
||
| 84 | * @param {number} [concurrency=1] - An `integer` for determining how many
|
||
| 85 | * `worker` functions should be run in parallel. If omitted, the concurrency
|
||
| 86 | * defaults to `1`. If the concurrency is `0`, an error is thrown.
|
||
| 87 | * @returns {module:ControlFlow.QueueObject} A queue object to manage the tasks. Callbacks can
|
||
| 88 | * attached as certain properties to listen for specific events during the
|
||
| 89 | * lifecycle of the queue.
|
||
| 90 | * @example
|
||
| 91 | *
|
||
| 92 | * // create a queue object with concurrency 2
|
||
| 93 | * var q = async.queue(function(task, callback) {
|
||
| 94 | * console.log('hello ' + task.name);
|
||
| 95 | * callback();
|
||
| 96 | * }, 2);
|
||
| 97 | *
|
||
| 98 | * // assign a callback
|
||
| 99 | * q.drain = function() {
|
||
| 100 | * console.log('all items have been processed');
|
||
| 101 | * };
|
||
| 102 | *
|
||
| 103 | * // add some items to the queue
|
||
| 104 | * q.push({name: 'foo'}, function(err) {
|
||
| 105 | * console.log('finished processing foo');
|
||
| 106 | * });
|
||
| 107 | * q.push({name: 'bar'}, function (err) {
|
||
| 108 | * console.log('finished processing bar');
|
||
| 109 | * });
|
||
| 110 | *
|
||
| 111 | * // add some items to the queue (batch-wise)
|
||
| 112 | * q.push([{name: 'baz'},{name: 'bay'},{name: 'bax'}], function(err) {
|
||
| 113 | * console.log('finished processing item');
|
||
| 114 | * });
|
||
| 115 | *
|
||
| 116 | * // add some items to the front of the queue
|
||
| 117 | * q.unshift({name: 'bar'}, function (err) {
|
||
| 118 | * console.log('finished processing bar');
|
||
| 119 | * });
|
||
| 120 | */ |