diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2024-05-14 14:05:49 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2024-05-14 14:05:49 +0800 |
| commit | 06823fbf1c2e763a5bf76c3990ca98fbbcd98691 (patch) | |
| tree | 4280bece3888d12a022093bf1a9cd1b049393602 /node_modules/fastq | |
| parent | 1368909b3cd552dbb0d12d5863c597f5be46177d (diff) | |
updated node_modules
Diffstat (limited to 'node_modules/fastq')
| -rw-r--r-- | node_modules/fastq/README.md | 3 | ||||
| -rw-r--r-- | node_modules/fastq/package.json | 2 | ||||
| -rw-r--r-- | node_modules/fastq/queue.js | 45 | ||||
| -rw-r--r-- | node_modules/fastq/test/test.js | 90 |
4 files changed, 109 insertions, 31 deletions
diff --git a/node_modules/fastq/README.md b/node_modules/fastq/README.md index 8a25fef8..af5feeee 100644 --- a/node_modules/fastq/README.md +++ b/node_modules/fastq/README.md @@ -2,7 +2,6 @@ ![ci][ci-url] [![npm version][npm-badge]][npm-url] -[![Dependency Status][david-badge]][david-url] Fast, in memory work queue. @@ -305,5 +304,3 @@ ISC [ci-url]: https://github.com/mcollina/fastq/workflows/ci/badge.svg [npm-badge]: https://badge.fury.io/js/fastq.svg [npm-url]: https://badge.fury.io/js/fastq -[david-badge]: https://david-dm.org/mcollina/fastq.svg -[david-url]: https://david-dm.org/mcollina/fastq diff --git a/node_modules/fastq/package.json b/node_modules/fastq/package.json index d0a20e0e..44655bc7 100644 --- a/node_modules/fastq/package.json +++ b/node_modules/fastq/package.json @@ -1,6 +1,6 @@ { "name": "fastq", - "version": "1.16.0", + "version": "1.17.1", "description": "Fast, in memory work queue", "main": "queue.js", "scripts": { diff --git a/node_modules/fastq/queue.js b/node_modules/fastq/queue.js index d5a8406d..a9d0fa95 100644 --- a/node_modules/fastq/queue.js +++ b/node_modules/fastq/queue.js @@ -4,15 +4,15 @@ var reusify = require('reusify') -function fastqueue (context, worker, concurrency) { +function fastqueue (context, worker, _concurrency) { if (typeof context === 'function') { - concurrency = worker + _concurrency = worker worker = context context = null } - if (concurrency < 1) { - throw new Error('fastqueue concurrency must be greater than 1') + if (!(_concurrency >= 1)) { + throw new Error('fastqueue concurrency must be equal to or greater than 1') } var cache = reusify(Task) @@ -27,7 +27,23 @@ function fastqueue (context, worker, concurrency) { saturated: noop, pause: pause, paused: false, - concurrency: concurrency, + + get concurrency () { + return _concurrency + }, + set concurrency (value) { + if (!(value >= 1)) { + throw new Error('fastqueue concurrency must be equal to or greater than 1') + } + _concurrency = value + + if (self.paused) return + for (; queueHead && _running < _concurrency;) { + _running++ + release() + } + }, + running: running, resume: resume, idle: idle, @@ -77,7 +93,12 @@ function fastqueue (context, worker, concurrency) { function resume () { if (!self.paused) return self.paused = false - for (var i = 0; i < self.concurrency; i++) { + if (queueHead === null) { + _running++ + release() + return + } + for (; queueHead && _running < _concurrency;) { _running++ release() } @@ -96,7 +117,7 @@ function fastqueue (context, worker, concurrency) { current.callback = done || noop current.errorHandler = errorHandler - if (_running === self.concurrency || self.paused) { + if (_running >= _concurrency || self.paused) { if (queueTail) { queueTail.next = current queueTail = current @@ -120,7 +141,7 @@ function fastqueue (context, worker, concurrency) { current.callback = done || noop current.errorHandler = errorHandler - if (_running === self.concurrency || self.paused) { + if (_running >= _concurrency || self.paused) { if (queueHead) { current.next = queueHead queueHead = current @@ -140,7 +161,7 @@ function fastqueue (context, worker, concurrency) { cache.release(holder) } var next = queueHead - if (next) { + if (next && _running <= _concurrency) { if (!self.paused) { if (queueTail === queueHead) { queueTail = null @@ -203,9 +224,9 @@ function Task () { } } -function queueAsPromised (context, worker, concurrency) { +function queueAsPromised (context, worker, _concurrency) { if (typeof context === 'function') { - concurrency = worker + _concurrency = worker worker = context context = null } @@ -217,7 +238,7 @@ function queueAsPromised (context, worker, concurrency) { }, cb) } - var queue = fastqueue(context, asyncWrapper, concurrency) + var queue = fastqueue(context, asyncWrapper, _concurrency) var pushCb = queue.push var unshiftCb = queue.unshift diff --git a/node_modules/fastq/test/test.js b/node_modules/fastq/test/test.js index accbaf94..ceed7a7b 100644 --- a/node_modules/fastq/test/test.js +++ b/node_modules/fastq/test/test.js @@ -6,10 +6,22 @@ var test = require('tape') var buildQueue = require('../') test('concurrency', function (t) { - t.plan(2) + t.plan(6) t.throws(buildQueue.bind(null, worker, 0)) + t.throws(buildQueue.bind(null, worker, NaN)) t.doesNotThrow(buildQueue.bind(null, worker, 1)) + var queue = buildQueue(worker, 1) + t.throws(function () { + queue.concurrency = 0 + }) + t.throws(function () { + queue.concurrency = NaN + }) + t.doesNotThrow(function () { + queue.concurrency = 2 + }) + function worker (arg, cb) { cb(null, true) } @@ -137,10 +149,11 @@ test('drain', function (t) { }) test('pause && resume', function (t) { - t.plan(7) + t.plan(13) var queue = buildQueue(worker, 1) var worked = false + var expected = [42, 24] t.notOk(queue.paused, 'it should not be paused') @@ -151,26 +164,33 @@ test('pause && resume', function (t) { t.equal(result, true, 'result matches') }) + queue.push(24, function (err, result) { + t.error(err, 'no error') + t.equal(result, true, 'result matches') + }) + t.notOk(worked, 'it should be paused') t.ok(queue.paused, 'it should be paused') queue.resume() + queue.pause() + queue.resume() queue.resume() // second resume is a no-op - t.notOk(queue.paused, 'it should not be paused') - function worker (arg, cb) { - t.equal(arg, 42) + t.notOk(queue.paused, 'it should not be paused') + t.ok(queue.running() <= queue.concurrency, 'should respect the concurrency') + t.equal(arg, expected.shift()) worked = true - cb(null, true) + process.nextTick(function () { cb(null, true) }) } }) test('pause in flight && resume', function (t) { - t.plan(9) + t.plan(16) var queue = buildQueue(worker, 1) - var expected = [42, 24] + var expected = [42, 24, 12] t.notOk(queue.paused, 'it should not be paused') @@ -178,7 +198,11 @@ test('pause in flight && resume', function (t) { t.error(err, 'no error') t.equal(result, true, 'result matches') t.ok(queue.paused, 'it should be paused') - process.nextTick(function () { queue.resume() }) + process.nextTick(function () { + queue.resume() + queue.pause() + queue.resume() + }) }) queue.push(24, function (err, result) { @@ -187,40 +211,60 @@ test('pause in flight && resume', function (t) { t.notOk(queue.paused, 'it should not be paused') }) + queue.push(12, function (err, result) { + t.error(err, 'no error') + t.equal(result, true, 'result matches') + t.notOk(queue.paused, 'it should not be paused') + }) + queue.pause() function worker (arg, cb) { + t.ok(queue.running() <= queue.concurrency, 'should respect the concurrency') t.equal(arg, expected.shift()) process.nextTick(function () { cb(null, true) }) } }) test('altering concurrency', function (t) { - t.plan(7) + t.plan(24) var queue = buildQueue(worker, 1) - var count = 0 - - queue.pause() queue.push(24, workDone) queue.push(24, workDone) + queue.push(24, workDone) + + queue.pause() + queue.concurrency = 3 // concurrency changes are ignored while paused queue.concurrency = 2 queue.resume() t.equal(queue.running(), 2, '2 jobs running') + queue.concurrency = 3 + + t.equal(queue.running(), 3, '3 jobs running') + + queue.concurrency = 1 + + t.equal(queue.running(), 3, '3 jobs running') // running jobs can't be killed + + queue.push(24, workDone) + queue.push(24, workDone) + queue.push(24, workDone) + queue.push(24, workDone) + function workDone (err, result) { t.error(err, 'no error') t.equal(result, true, 'result matches') } function worker (arg, cb) { - t.equal(0, count, 'works in parallel') + t.ok(queue.running() <= queue.concurrency, 'should respect the concurrency') setImmediate(function () { - count++ cb(null, true) }) } @@ -580,3 +624,19 @@ test('unshift with worker throwing error', function (t) { t.match(err.message, /test error/, 'error message should be "test error"') }) }) + +test('pause/resume should trigger drain event', function (t) { + t.plan(1) + + var queue = buildQueue(worker, 1) + queue.pause() + queue.drain = function () { + t.pass('drain should be called') + } + + function worker (arg, cb) { + cb(null, true) + } + + queue.resume() +}) |
