mirror of
https://github.com/fooflington/selfdefined.git
synced 2025-09-16 04:29:06 +00:00
update
This commit is contained in:
10
node_modules/fastq/.travis.yml
generated
vendored
Normal file
10
node_modules/fastq/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "10"
|
||||
- "8"
|
||||
- "6"
|
||||
- "5"
|
||||
- "4"
|
||||
- "0.12"
|
||||
- "0.10"
|
||||
- "iojs"
|
13
node_modules/fastq/LICENSE
generated
vendored
Normal file
13
node_modules/fastq/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
Copyright (c) 2015, Matteo Collina <matteo.collina@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
183
node_modules/fastq/README.md
generated
vendored
Normal file
183
node_modules/fastq/README.md
generated
vendored
Normal file
@@ -0,0 +1,183 @@
|
||||
# fastq [](http://travis-ci.org/mcollina/fastq)
|
||||
|
||||
Fast, in memory work queue. `fastq` is API compatible with
|
||||
[`async.queue`](https://github.com/caolan/async#queueworker-concurrency)
|
||||
|
||||
Benchmarks (1 million tasks):
|
||||
|
||||
* setImmediate: 1359ms
|
||||
* fastq: 1492ms
|
||||
* async.queue: 4039ms
|
||||
* neoAsync.queue: 4476ms
|
||||
|
||||
Obtained on node 4.2.2, on a MacBook Pro 2014 (i7, 16GB of RAM).
|
||||
|
||||
If you need zero-overhead series function call, check out
|
||||
[fastseries](http://npm.im/fastseries). For zero-overhead parallel
|
||||
function call, check out [fastparallel](http://npm.im/fastparallel).
|
||||
|
||||
[](https://github.com/feross/standard)
|
||||
|
||||
* <a href="#install">Installation</a>
|
||||
* <a href="#basic">Basic Example</a>
|
||||
* <a href="#api">API</a>
|
||||
* <a href="#licence">Licence & copyright</a>
|
||||
|
||||
## Install
|
||||
|
||||
`npm i fastq --save`
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
'use strict'
|
||||
|
||||
var queue = require('fastq')(worker, 1)
|
||||
|
||||
queue.push(42, function (err, result) {
|
||||
if (err) { throw err }
|
||||
console.log('the result is', result)
|
||||
})
|
||||
|
||||
function worker (arg, cb) {
|
||||
cb(null, 42 * 2)
|
||||
}
|
||||
```
|
||||
|
||||
### Setting this
|
||||
|
||||
```js
|
||||
'use strict'
|
||||
|
||||
var that = { hello: 'world' }
|
||||
var queue = require('fastq')(that, worker, 1)
|
||||
|
||||
queue.push(42, function (err, result) {
|
||||
if (err) { throw err }
|
||||
console.log(this)
|
||||
console.log('the result is', result)
|
||||
})
|
||||
|
||||
function worker (arg, cb) {
|
||||
console.log(this)
|
||||
cb(null, 42 * 2)
|
||||
}
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
* <a href="#fastqueue"><code>fastqueue()</code></a>
|
||||
* <a href="#push"><code>queue#<b>push()</b></code></a>
|
||||
* <a href="#unshift"><code>queue#<b>unshift()</b></code></a>
|
||||
* <a href="#pause"><code>queue#<b>pause()</b></code></a>
|
||||
* <a href="#resume"><code>queue#<b>resume()</b></code></a>
|
||||
* <a href="#idle"><code>queue#<b>idle()</b></code></a>
|
||||
* <a href="#length"><code>queue#<b>length()</b></code></a>
|
||||
* <a href="#kill"><code>queue#<b>kill()</b></code></a>
|
||||
* <a href="#killAndDrain"><code>queue#<b>killAndDrain()</b></code></a>
|
||||
* <a href="#concurrency"><code>queue#<b>concurrency</b></code></a>
|
||||
* <a href="#drain"><code>queue#<b>drain</b></code></a>
|
||||
* <a href="#empty"><code>queue#<b>empty</b></code></a>
|
||||
* <a href="#saturated"><code>queue#<b>saturated</b></code></a>
|
||||
|
||||
-------------------------------------------------------
|
||||
<a name="fastqueue"></a>
|
||||
### fastqueue([that], worker, concurrency)
|
||||
|
||||
Creates a new queue.
|
||||
|
||||
Arguments:
|
||||
|
||||
* `that`, optional context of the `worker` function.
|
||||
* `worker`, worker function, it would be called with `that` as `this`,
|
||||
if that is specified.
|
||||
* `concurrency`, number of concurrent tasks that could be executed in
|
||||
parallel.
|
||||
|
||||
-------------------------------------------------------
|
||||
<a name="push"></a>
|
||||
### queue.push(task, done)
|
||||
|
||||
Add a task at the end of the queue. `done(err, result)` will be called
|
||||
when the task was processed.
|
||||
|
||||
-------------------------------------------------------
|
||||
<a name="unshift"></a>
|
||||
### queue.unshift(task, done)
|
||||
|
||||
Add a task at the beginning of the queue. `done(err, result)` will be called
|
||||
when the task was processed.
|
||||
|
||||
-------------------------------------------------------
|
||||
<a name="pause"></a>
|
||||
### queue.pause()
|
||||
|
||||
Pause the processing of tasks. Currently worked tasks are not
|
||||
stopped.
|
||||
|
||||
-------------------------------------------------------
|
||||
<a name="resume"></a>
|
||||
### queue.resume()
|
||||
|
||||
Resume the processing of tasks.
|
||||
|
||||
-------------------------------------------------------
|
||||
<a name="idle"></a>
|
||||
### queue.idle()
|
||||
|
||||
Returns `false` if there are tasks being processed or waiting to be processed.
|
||||
`true` otherwise.
|
||||
|
||||
-------------------------------------------------------
|
||||
<a name="length"></a>
|
||||
### queue.length()
|
||||
|
||||
Returns the number of tasks waiting to be processed (in the queue).
|
||||
|
||||
-------------------------------------------------------
|
||||
<a name="kill"></a>
|
||||
### queue.kill()
|
||||
|
||||
Removes all tasks waiting to be processed, and reset `drain` to an empty
|
||||
function.
|
||||
|
||||
-------------------------------------------------------
|
||||
<a name="killAndDrain"></a>
|
||||
### queue.killAndDrain()
|
||||
|
||||
Same than `kill` but the `drain` function will be called before reset to empty.
|
||||
|
||||
-------------------------------------------------------
|
||||
<a name="concurrency"></a>
|
||||
### queue.concurrency
|
||||
|
||||
Property that returns the number of concurrent tasks that could be executed in
|
||||
parallel. It can be altered at runtime.
|
||||
|
||||
-------------------------------------------------------
|
||||
<a name="drain"></a>
|
||||
### queue.drain
|
||||
|
||||
Function that will be called when the last
|
||||
item from the queue has been processed by a worker.
|
||||
It can be altered at runtime.
|
||||
|
||||
-------------------------------------------------------
|
||||
<a name="empty"></a>
|
||||
### queue.empty
|
||||
|
||||
Function that will be called when the last
|
||||
item from the queue has been assigned to a worker.
|
||||
It can be altered at runtime.
|
||||
|
||||
-------------------------------------------------------
|
||||
<a name="saturated"></a>
|
||||
### queue.saturated
|
||||
|
||||
Function that will be called when the queue hits the concurrency
|
||||
limit.
|
||||
It can be altered at runtime.
|
||||
|
||||
## License
|
||||
|
||||
ISC
|
58
node_modules/fastq/bench.js
generated
vendored
Normal file
58
node_modules/fastq/bench.js
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
'use strict'
|
||||
|
||||
var max = 1000000
|
||||
var fastqueue = require('./')(worker, 1)
|
||||
var async = require('async')
|
||||
var neo = require('neo-async')
|
||||
var asyncqueue = async.queue(worker, 1)
|
||||
var neoqueue = neo.queue(worker, 1)
|
||||
|
||||
function bench (func, done) {
|
||||
var key = max + '*' + func.name
|
||||
var count = -1
|
||||
|
||||
console.time(key)
|
||||
end()
|
||||
|
||||
function end () {
|
||||
if (++count < max) {
|
||||
func(end)
|
||||
} else {
|
||||
console.timeEnd(key)
|
||||
if (done) {
|
||||
done()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function benchFastQ (done) {
|
||||
fastqueue.push(42, done)
|
||||
}
|
||||
|
||||
function benchAsyncQueue (done) {
|
||||
asyncqueue.push(42, done)
|
||||
}
|
||||
|
||||
function benchNeoQueue (done) {
|
||||
neoqueue.push(42, done)
|
||||
}
|
||||
|
||||
function worker (arg, cb) {
|
||||
setImmediate(cb)
|
||||
}
|
||||
|
||||
function benchSetImmediate (cb) {
|
||||
worker(42, cb)
|
||||
}
|
||||
|
||||
function runBench (done) {
|
||||
async.eachSeries([
|
||||
benchSetImmediate,
|
||||
benchFastQ,
|
||||
benchNeoQueue,
|
||||
benchAsyncQueue
|
||||
], bench, done)
|
||||
}
|
||||
|
||||
runBench(runBench)
|
12
node_modules/fastq/example.js
generated
vendored
Normal file
12
node_modules/fastq/example.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
'use strict'
|
||||
|
||||
var queue = require('./')(worker, 1)
|
||||
|
||||
queue.push(42, function (err, result) {
|
||||
if (err) { throw err }
|
||||
console.log('the result is', result)
|
||||
})
|
||||
|
||||
function worker (arg, cb) {
|
||||
cb(null, 42 * 2)
|
||||
}
|
24
node_modules/fastq/index.d.ts
generated
vendored
Normal file
24
node_modules/fastq/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
declare function fastq<T>(context: T, worker: fastq.worker<T>, concurrency: number): fastq.queue
|
||||
declare function fastq<T>(worker: fastq.worker<T>, concurrency: number): fastq.queue
|
||||
|
||||
declare namespace fastq {
|
||||
type worker<T> = (this: T, arg: any, cb: () => void) => void
|
||||
type done = (err: Error, result: any) => void
|
||||
|
||||
interface queue {
|
||||
push(task: any, done: done): void
|
||||
unshift(task: any, done: done): void
|
||||
pause(): any
|
||||
resume(): any
|
||||
idle(): boolean
|
||||
length(): number
|
||||
kill(): any
|
||||
killAndDrain(): any
|
||||
concurrency: number
|
||||
drain(): any
|
||||
empty: () => void
|
||||
saturated: () => void
|
||||
}
|
||||
}
|
||||
|
||||
export = fastq
|
74
node_modules/fastq/package.json
generated
vendored
Normal file
74
node_modules/fastq/package.json
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"fastq@1.6.0",
|
||||
"/Users/tatiana/selfdefined"
|
||||
]
|
||||
],
|
||||
"_from": "fastq@1.6.0",
|
||||
"_id": "fastq@1.6.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-jmxqQ3Z/nXoeyDmWAzF9kH1aGZSis6e/SbfPmJpUnyZ0ogr6iscHQaml4wsEepEWSdtmpy+eVXmCRIMpxaXqOA==",
|
||||
"_location": "/fastq",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "fastq@1.6.0",
|
||||
"name": "fastq",
|
||||
"escapedName": "fastq",
|
||||
"rawSpec": "1.6.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "1.6.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/@nodelib/fs.walk"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/fastq/-/fastq-1.6.0.tgz",
|
||||
"_spec": "1.6.0",
|
||||
"_where": "/Users/tatiana/selfdefined",
|
||||
"author": {
|
||||
"name": "Matteo Collina",
|
||||
"email": "hello@matteocollina.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/mcollina/fastq/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"reusify": "^1.0.0"
|
||||
},
|
||||
"description": "Fast, in memory work queue",
|
||||
"devDependencies": {
|
||||
"async": "^2.6.1",
|
||||
"neo-async": "^2.5.1",
|
||||
"pre-commit": "^1.2.2",
|
||||
"standard": "^11.0.0",
|
||||
"tap-spec": "^4.1.2",
|
||||
"tape": "^4.9.0",
|
||||
"typescript": "^2.9.1"
|
||||
},
|
||||
"homepage": "https://github.com/mcollina/fastq#readme",
|
||||
"keywords": [
|
||||
"fast",
|
||||
"queue",
|
||||
"async",
|
||||
"worker"
|
||||
],
|
||||
"license": "ISC",
|
||||
"main": "queue.js",
|
||||
"name": "fastq",
|
||||
"pre-commit": [
|
||||
"lint",
|
||||
"test"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/mcollina/fastq.git"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "standard",
|
||||
"test": "standard && tape test/test.js | tap-spec && npm run typescript",
|
||||
"typescript": "tsc --project ./test/tsconfig.json"
|
||||
},
|
||||
"version": "1.6.0"
|
||||
}
|
173
node_modules/fastq/queue.js
generated
vendored
Normal file
173
node_modules/fastq/queue.js
generated
vendored
Normal file
@@ -0,0 +1,173 @@
|
||||
'use strict'
|
||||
|
||||
var reusify = require('reusify')
|
||||
|
||||
function fastqueue (context, worker, concurrency) {
|
||||
if (typeof context === 'function') {
|
||||
concurrency = worker
|
||||
worker = context
|
||||
context = null
|
||||
}
|
||||
|
||||
var cache = reusify(Task)
|
||||
var queueHead = null
|
||||
var queueTail = null
|
||||
var _running = 0
|
||||
|
||||
var self = {
|
||||
push: push,
|
||||
drain: noop,
|
||||
saturated: noop,
|
||||
pause: pause,
|
||||
paused: false,
|
||||
concurrency: concurrency,
|
||||
running: running,
|
||||
resume: resume,
|
||||
idle: idle,
|
||||
length: length,
|
||||
unshift: unshift,
|
||||
empty: noop,
|
||||
kill: kill,
|
||||
killAndDrain: killAndDrain
|
||||
}
|
||||
|
||||
return self
|
||||
|
||||
function running () {
|
||||
return _running
|
||||
}
|
||||
|
||||
function pause () {
|
||||
self.paused = true
|
||||
}
|
||||
|
||||
function length () {
|
||||
var current = queueHead
|
||||
var counter = 0
|
||||
|
||||
while (current) {
|
||||
current = current.next
|
||||
counter++
|
||||
}
|
||||
|
||||
return counter
|
||||
}
|
||||
|
||||
function resume () {
|
||||
if (!self.paused) return
|
||||
self.paused = false
|
||||
for (var i = 0; i < self.concurrency; i++) {
|
||||
_running++
|
||||
release()
|
||||
}
|
||||
}
|
||||
|
||||
function idle () {
|
||||
return _running === 0 && self.length() === 0
|
||||
}
|
||||
|
||||
function push (value, done) {
|
||||
var current = cache.get()
|
||||
|
||||
current.context = context
|
||||
current.release = release
|
||||
current.value = value
|
||||
current.callback = done || noop
|
||||
|
||||
if (_running === self.concurrency || self.paused) {
|
||||
if (queueTail) {
|
||||
queueTail.next = current
|
||||
queueTail = current
|
||||
} else {
|
||||
queueHead = current
|
||||
queueTail = current
|
||||
self.saturated()
|
||||
}
|
||||
} else {
|
||||
_running++
|
||||
worker.call(context, current.value, current.worked)
|
||||
}
|
||||
}
|
||||
|
||||
function unshift (value, done) {
|
||||
var current = cache.get()
|
||||
|
||||
current.context = context
|
||||
current.release = release
|
||||
current.value = value
|
||||
current.callback = done || noop
|
||||
|
||||
if (_running === self.concurrency || self.paused) {
|
||||
if (queueHead) {
|
||||
current.next = queueHead
|
||||
queueHead = current
|
||||
} else {
|
||||
queueHead = current
|
||||
queueTail = current
|
||||
self.saturated()
|
||||
}
|
||||
} else {
|
||||
_running++
|
||||
worker.call(context, current.value, current.worked)
|
||||
}
|
||||
}
|
||||
|
||||
function release (holder) {
|
||||
if (holder) {
|
||||
cache.release(holder)
|
||||
}
|
||||
var next = queueHead
|
||||
if (next) {
|
||||
if (!self.paused) {
|
||||
if (queueTail === queueHead) {
|
||||
queueTail = null
|
||||
}
|
||||
queueHead = next.next
|
||||
next.next = null
|
||||
worker.call(context, next.value, next.worked)
|
||||
if (queueTail === null) {
|
||||
self.empty()
|
||||
}
|
||||
} else {
|
||||
_running--
|
||||
}
|
||||
} else if (--_running === 0) {
|
||||
self.drain()
|
||||
}
|
||||
}
|
||||
|
||||
function kill () {
|
||||
queueHead = null
|
||||
queueTail = null
|
||||
self.drain = noop
|
||||
}
|
||||
|
||||
function killAndDrain () {
|
||||
queueHead = null
|
||||
queueTail = null
|
||||
self.drain()
|
||||
self.drain = noop
|
||||
}
|
||||
}
|
||||
|
||||
function noop () {}
|
||||
|
||||
function Task () {
|
||||
this.value = null
|
||||
this.callback = noop
|
||||
this.next = null
|
||||
this.release = noop
|
||||
this.context = null
|
||||
|
||||
var self = this
|
||||
|
||||
this.worked = function worked (err, result) {
|
||||
var callback = self.callback
|
||||
self.value = null
|
||||
self.callback = noop
|
||||
callback.call(self.context, err, result)
|
||||
self.release(self)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = fastqueue
|
37
node_modules/fastq/test/example.ts
generated
vendored
Normal file
37
node_modules/fastq/test/example.ts
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
import * as fastq from '../'
|
||||
|
||||
const queue = fastq({ hello: 'world' }, worker, 1)
|
||||
|
||||
queue.push(42, (err, done) => {
|
||||
if (err) throw err
|
||||
console.log('the result is', done)
|
||||
})
|
||||
|
||||
queue.concurrency
|
||||
|
||||
queue.drain()
|
||||
|
||||
queue.empty = () => undefined
|
||||
|
||||
queue.idle()
|
||||
|
||||
queue.kill()
|
||||
|
||||
queue.killAndDrain()
|
||||
|
||||
queue.length
|
||||
|
||||
queue.pause()
|
||||
|
||||
queue.resume()
|
||||
|
||||
queue.saturated = () => undefined
|
||||
|
||||
queue.unshift(42, (err, done) => {
|
||||
if (err) throw err
|
||||
console.log('the result is', done)
|
||||
})
|
||||
|
||||
function worker(arg: any, cb: any) {
|
||||
cb(null, 42 * 2)
|
||||
}
|
482
node_modules/fastq/test/test.js
generated
vendored
Normal file
482
node_modules/fastq/test/test.js
generated
vendored
Normal file
@@ -0,0 +1,482 @@
|
||||
'use strict'
|
||||
|
||||
var test = require('tape')
|
||||
var buildQueue = require('../')
|
||||
|
||||
test('worker execution', function (t) {
|
||||
t.plan(3)
|
||||
|
||||
var queue = buildQueue(worker, 1)
|
||||
|
||||
queue.push(42, function (err, result) {
|
||||
t.error(err, 'no error')
|
||||
t.equal(result, true, 'result matches')
|
||||
})
|
||||
|
||||
function worker (arg, cb) {
|
||||
t.equal(arg, 42)
|
||||
cb(null, true)
|
||||
}
|
||||
})
|
||||
|
||||
test('limit', function (t) {
|
||||
t.plan(4)
|
||||
|
||||
var expected = [10, 0]
|
||||
var queue = buildQueue(worker, 1)
|
||||
|
||||
queue.push(10, result)
|
||||
queue.push(0, result)
|
||||
|
||||
function result (err, arg) {
|
||||
t.error(err, 'no error')
|
||||
t.equal(arg, expected.shift(), 'the result matches')
|
||||
}
|
||||
|
||||
function worker (arg, cb) {
|
||||
setTimeout(cb, arg, null, arg)
|
||||
}
|
||||
})
|
||||
|
||||
test('multiple executions', function (t) {
|
||||
t.plan(15)
|
||||
|
||||
var queue = buildQueue(worker, 1)
|
||||
var toExec = [1, 2, 3, 4, 5]
|
||||
var count = 0
|
||||
|
||||
toExec.forEach(function (task) {
|
||||
queue.push(task, done)
|
||||
})
|
||||
|
||||
function done (err, result) {
|
||||
t.error(err, 'no error')
|
||||
t.equal(result, toExec[count - 1], 'the result matches')
|
||||
}
|
||||
|
||||
function worker (arg, cb) {
|
||||
t.equal(arg, toExec[count], 'arg matches')
|
||||
count++
|
||||
setImmediate(cb, null, arg)
|
||||
}
|
||||
})
|
||||
|
||||
test('multiple executions, one after another', function (t) {
|
||||
t.plan(15)
|
||||
|
||||
var queue = buildQueue(worker, 1)
|
||||
var toExec = [1, 2, 3, 4, 5]
|
||||
var count = 0
|
||||
|
||||
queue.push(toExec[0], done)
|
||||
|
||||
function done (err, result) {
|
||||
t.error(err, 'no error')
|
||||
t.equal(result, toExec[count - 1], 'the result matches')
|
||||
if (count < toExec.length) {
|
||||
queue.push(toExec[count], done)
|
||||
}
|
||||
}
|
||||
|
||||
function worker (arg, cb) {
|
||||
console.log('received', arg)
|
||||
t.equal(arg, toExec[count], 'arg matches')
|
||||
count++
|
||||
setImmediate(cb, null, arg)
|
||||
}
|
||||
})
|
||||
|
||||
test('set this', function (t) {
|
||||
t.plan(3)
|
||||
|
||||
var that = {}
|
||||
var queue = buildQueue(that, worker, 1)
|
||||
|
||||
queue.push(42, function (err, result) {
|
||||
t.error(err, 'no error')
|
||||
t.equal(this, that, 'this matches')
|
||||
})
|
||||
|
||||
function worker (arg, cb) {
|
||||
t.equal(this, that, 'this matches')
|
||||
cb(null, true)
|
||||
}
|
||||
})
|
||||
|
||||
test('drain', function (t) {
|
||||
t.plan(4)
|
||||
|
||||
var queue = buildQueue(worker, 1)
|
||||
var worked = false
|
||||
|
||||
queue.push(42, function (err, result) {
|
||||
t.error(err, 'no error')
|
||||
t.equal(result, true, 'result matches')
|
||||
})
|
||||
|
||||
queue.drain = function () {
|
||||
t.equal(true, worked, 'drained')
|
||||
}
|
||||
|
||||
function worker (arg, cb) {
|
||||
t.equal(arg, 42)
|
||||
worked = true
|
||||
setImmediate(cb, null, true)
|
||||
}
|
||||
})
|
||||
|
||||
test('pause && resume', function (t) {
|
||||
t.plan(7)
|
||||
|
||||
var queue = buildQueue(worker, 1)
|
||||
var worked = false
|
||||
|
||||
t.notOk(queue.paused, 'it should not be paused')
|
||||
|
||||
queue.pause()
|
||||
|
||||
queue.push(42, 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()
|
||||
|
||||
t.notOk(queue.paused, 'it should not be paused')
|
||||
|
||||
function worker (arg, cb) {
|
||||
t.equal(arg, 42)
|
||||
worked = true
|
||||
cb(null, true)
|
||||
}
|
||||
})
|
||||
|
||||
test('altering concurrency', function (t) {
|
||||
t.plan(7)
|
||||
|
||||
var queue = buildQueue(worker, 1)
|
||||
var count = 0
|
||||
|
||||
queue.pause()
|
||||
|
||||
queue.push(24, workDone)
|
||||
queue.push(24, workDone)
|
||||
|
||||
queue.concurrency = 2
|
||||
|
||||
queue.resume()
|
||||
|
||||
t.equal(queue.running(), 2, '2 jobs running')
|
||||
|
||||
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')
|
||||
setImmediate(function () {
|
||||
count++
|
||||
cb(null, true)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
test('idle()', function (t) {
|
||||
t.plan(12)
|
||||
|
||||
var queue = buildQueue(worker, 1)
|
||||
|
||||
t.ok(queue.idle(), 'queue is idle')
|
||||
|
||||
queue.push(42, function (err, result) {
|
||||
t.error(err, 'no error')
|
||||
t.equal(result, true, 'result matches')
|
||||
t.notOk(queue.idle(), 'queue is not idle')
|
||||
})
|
||||
|
||||
queue.push(42, function (err, result) {
|
||||
t.error(err, 'no error')
|
||||
t.equal(result, true, 'result matches')
|
||||
// it will go idle after executing this function
|
||||
setImmediate(function () {
|
||||
t.ok(queue.idle(), 'queue is now idle')
|
||||
})
|
||||
})
|
||||
|
||||
t.notOk(queue.idle(), 'queue is not idle')
|
||||
|
||||
function worker (arg, cb) {
|
||||
t.notOk(queue.idle(), 'queue is not idle')
|
||||
t.equal(arg, 42)
|
||||
setImmediate(cb, null, true)
|
||||
}
|
||||
})
|
||||
|
||||
test('saturated', function (t) {
|
||||
t.plan(9)
|
||||
|
||||
var queue = buildQueue(worker, 1)
|
||||
var preworked = 0
|
||||
var worked = 0
|
||||
|
||||
queue.saturated = function () {
|
||||
t.pass('saturated')
|
||||
t.equal(preworked, 1, 'started 1 task')
|
||||
t.equal(worked, 0, 'worked zero task')
|
||||
}
|
||||
|
||||
queue.push(42, done)
|
||||
queue.push(42, done)
|
||||
|
||||
function done (err, result) {
|
||||
t.error(err, 'no error')
|
||||
t.equal(result, true, 'result matches')
|
||||
}
|
||||
|
||||
function worker (arg, cb) {
|
||||
t.equal(arg, 42)
|
||||
preworked++
|
||||
setImmediate(function () {
|
||||
worked++
|
||||
cb(null, true)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
test('length', function (t) {
|
||||
t.plan(7)
|
||||
|
||||
var queue = buildQueue(worker, 1)
|
||||
|
||||
t.equal(queue.length(), 0, 'nothing waiting')
|
||||
queue.push(42, done)
|
||||
t.equal(queue.length(), 0, 'nothing waiting')
|
||||
queue.push(42, done)
|
||||
t.equal(queue.length(), 1, 'one task waiting')
|
||||
queue.push(42, done)
|
||||
t.equal(queue.length(), 2, 'two tasks waiting')
|
||||
|
||||
function done (err, result) {
|
||||
t.error(err, 'no error')
|
||||
}
|
||||
|
||||
function worker (arg, cb) {
|
||||
setImmediate(function () {
|
||||
cb(null, true)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
test('unshift', function (t) {
|
||||
t.plan(8)
|
||||
|
||||
var queue = buildQueue(worker, 1)
|
||||
var expected = [1, 2, 3, 4]
|
||||
|
||||
queue.push(1, done)
|
||||
queue.push(4, done)
|
||||
queue.unshift(3, done)
|
||||
queue.unshift(2, done)
|
||||
|
||||
function done (err, result) {
|
||||
t.error(err, 'no error')
|
||||
}
|
||||
|
||||
function worker (arg, cb) {
|
||||
t.equal(expected.shift(), arg, 'tasks come in order')
|
||||
setImmediate(function () {
|
||||
cb(null, true)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
test('unshift && empty', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
var queue = buildQueue(worker, 1)
|
||||
var completed = false
|
||||
|
||||
queue.pause()
|
||||
|
||||
queue.empty = function () {
|
||||
t.notOk(completed, 'the task has not completed yet')
|
||||
}
|
||||
|
||||
queue.unshift(1, done)
|
||||
|
||||
queue.resume()
|
||||
|
||||
function done (err, result) {
|
||||
completed = true
|
||||
t.error(err, 'no error')
|
||||
}
|
||||
|
||||
function worker (arg, cb) {
|
||||
setImmediate(function () {
|
||||
cb(null, true)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
test('push && empty', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
var queue = buildQueue(worker, 1)
|
||||
var completed = false
|
||||
|
||||
queue.pause()
|
||||
|
||||
queue.empty = function () {
|
||||
t.notOk(completed, 'the task has not completed yet')
|
||||
}
|
||||
|
||||
queue.push(1, done)
|
||||
|
||||
queue.resume()
|
||||
|
||||
function done (err, result) {
|
||||
completed = true
|
||||
t.error(err, 'no error')
|
||||
}
|
||||
|
||||
function worker (arg, cb) {
|
||||
setImmediate(function () {
|
||||
cb(null, true)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
test('kill', function (t) {
|
||||
t.plan(5)
|
||||
|
||||
var queue = buildQueue(worker, 1)
|
||||
var expected = [1]
|
||||
|
||||
var predrain = queue.drain
|
||||
|
||||
queue.drain = function drain () {
|
||||
t.fail('drain should never be called')
|
||||
}
|
||||
|
||||
queue.push(1, done)
|
||||
queue.push(4, done)
|
||||
queue.unshift(3, done)
|
||||
queue.unshift(2, done)
|
||||
queue.kill()
|
||||
|
||||
function done (err, result) {
|
||||
t.error(err, 'no error')
|
||||
setImmediate(function () {
|
||||
t.equal(queue.length(), 0, 'no queued tasks')
|
||||
t.equal(queue.running(), 0, 'no running tasks')
|
||||
t.equal(queue.drain, predrain, 'drain is back to default')
|
||||
})
|
||||
}
|
||||
|
||||
function worker (arg, cb) {
|
||||
t.equal(expected.shift(), arg, 'tasks come in order')
|
||||
setImmediate(function () {
|
||||
cb(null, true)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
test('killAndDrain', function (t) {
|
||||
t.plan(6)
|
||||
|
||||
var queue = buildQueue(worker, 1)
|
||||
var expected = [1]
|
||||
|
||||
var predrain = queue.drain
|
||||
|
||||
queue.drain = function drain () {
|
||||
t.pass('drain has been called')
|
||||
}
|
||||
|
||||
queue.push(1, done)
|
||||
queue.push(4, done)
|
||||
queue.unshift(3, done)
|
||||
queue.unshift(2, done)
|
||||
queue.killAndDrain()
|
||||
|
||||
function done (err, result) {
|
||||
t.error(err, 'no error')
|
||||
setImmediate(function () {
|
||||
t.equal(queue.length(), 0, 'no queued tasks')
|
||||
t.equal(queue.running(), 0, 'no running tasks')
|
||||
t.equal(queue.drain, predrain, 'drain is back to default')
|
||||
})
|
||||
}
|
||||
|
||||
function worker (arg, cb) {
|
||||
t.equal(expected.shift(), arg, 'tasks come in order')
|
||||
setImmediate(function () {
|
||||
cb(null, true)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
test('pause && idle', function (t) {
|
||||
t.plan(11)
|
||||
|
||||
var queue = buildQueue(worker, 1)
|
||||
var worked = false
|
||||
|
||||
t.notOk(queue.paused, 'it should not be paused')
|
||||
t.ok(queue.idle(), 'should be idle')
|
||||
|
||||
queue.pause()
|
||||
|
||||
queue.push(42, 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')
|
||||
t.notOk(queue.idle(), 'should not be idle')
|
||||
|
||||
queue.resume()
|
||||
|
||||
t.notOk(queue.paused, 'it should not be paused')
|
||||
t.notOk(queue.idle(), 'it should not be idle')
|
||||
|
||||
function worker (arg, cb) {
|
||||
t.equal(arg, 42)
|
||||
worked = true
|
||||
process.nextTick(cb.bind(null, null, true))
|
||||
process.nextTick(function () {
|
||||
t.ok(queue.idle(), 'is should be idle')
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
test('push without cb', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
var queue = buildQueue(worker, 1)
|
||||
|
||||
queue.push(42)
|
||||
|
||||
function worker (arg, cb) {
|
||||
t.equal(arg, 42)
|
||||
cb()
|
||||
}
|
||||
})
|
||||
|
||||
test('unshift without cb', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
var queue = buildQueue(worker, 1)
|
||||
|
||||
queue.unshift(42)
|
||||
|
||||
function worker (arg, cb) {
|
||||
t.equal(arg, 42)
|
||||
cb()
|
||||
}
|
||||
})
|
11
node_modules/fastq/test/tsconfig.json
generated
vendored
Normal file
11
node_modules/fastq/test/tsconfig.json
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"module": "commonjs",
|
||||
"noEmit": true,
|
||||
"strict": true,
|
||||
},
|
||||
"files": [
|
||||
"./example.ts"
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user