update, text, response
This commit is contained in:
70
node_modules/fastq/queue.js
generated
vendored
70
node_modules/fastq/queue.js
generated
vendored
@@ -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
|
||||
@@ -118,8 +139,9 @@ function fastqueue (context, worker, concurrency) {
|
||||
current.release = release
|
||||
current.value = value
|
||||
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
|
||||
@@ -139,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
|
||||
@@ -202,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
|
||||
}
|
||||
@@ -216,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
|
||||
@@ -266,19 +288,19 @@ function queueAsPromised (context, worker, concurrency) {
|
||||
}
|
||||
|
||||
function drained () {
|
||||
if (queue.idle()) {
|
||||
return new Promise(function (resolve) {
|
||||
resolve()
|
||||
})
|
||||
}
|
||||
|
||||
var previousDrain = queue.drain
|
||||
|
||||
var p = new Promise(function (resolve) {
|
||||
queue.drain = function () {
|
||||
previousDrain()
|
||||
resolve()
|
||||
}
|
||||
process.nextTick(function () {
|
||||
if (queue.idle()) {
|
||||
resolve()
|
||||
} else {
|
||||
var previousDrain = queue.drain
|
||||
queue.drain = function () {
|
||||
if (typeof previousDrain === 'function') previousDrain()
|
||||
resolve()
|
||||
queue.drain = previousDrain
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
return p
|
||||
|
||||
Reference in New Issue
Block a user