Projektstart
This commit is contained in:
11
backend/node_modules/fastparallel/.github/dependabot.yml
generated
vendored
Normal file
11
backend/node_modules/fastparallel/.github/dependabot.yml
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: npm
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: daily
|
||||
open-pull-requests-limit: 10
|
||||
ignore:
|
||||
- dependency-name: standard
|
||||
versions:
|
||||
- 16.0.3
|
||||
27
backend/node_modules/fastparallel/.github/workflows/ci.yml
generated
vendored
Normal file
27
backend/node_modules/fastparallel/.github/workflows/ci.yml
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
name: ci
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: ['0.10', '0.12', 4.x, 6.x, 8.x, 12.x, 14.x, 16.x]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
|
||||
- name: Install
|
||||
run: |
|
||||
npm install
|
||||
|
||||
- name: Run tests
|
||||
run: |
|
||||
npm run test
|
||||
14
backend/node_modules/fastparallel/LICENSE
generated
vendored
Normal file
14
backend/node_modules/fastparallel/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
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.
|
||||
|
||||
124
backend/node_modules/fastparallel/README.md
generated
vendored
Normal file
124
backend/node_modules/fastparallel/README.md
generated
vendored
Normal file
@@ -0,0 +1,124 @@
|
||||
# fastparallel [](https://github.com/mcollina/fastparallel/actions/workflows/ci.yml)
|
||||
|
||||
Zero-overhead parallel function call for node.js. Also supports each
|
||||
and map!
|
||||
|
||||
Benchmark for doing 3 calls `setImmediate` 1 million times:
|
||||
|
||||
```
|
||||
benchSetImmediate*1000000: 1378.514ms
|
||||
benchAsyncParallel*1000000: 1740.304ms
|
||||
benchAsyncEach*1000000: 1566.517ms
|
||||
benchAsyncMap*1000000: 1687.518ms
|
||||
benchNeoParallel*1000000: 1388.223ms
|
||||
benchNeoEach*1000000: 1473.006ms
|
||||
benchNeoMap*1000000: 1402.986ms
|
||||
benchInsyncParallel*1000000: 1957.863ms
|
||||
benchInsyncEach*1000000: 1383.822ms
|
||||
benchInsyncMap*1000000: 1822.954ms
|
||||
benchItemsParallel*1000000: 1690.118ms
|
||||
benchParallelize*1000000: 1570.064ms
|
||||
benchFastParallel*1000000: 1536.692ms
|
||||
benchFastParallelNoResults*1000000: 1363.145ms
|
||||
benchFastParallelEachResults*1000000: 1508.134ms
|
||||
benchFastParallelEach*1000000: 1325.314ms
|
||||
```
|
||||
|
||||
Obtained on node 12.18.2, on a dedicated server.
|
||||
|
||||
If you need zero-overhead series function call, check out
|
||||
[fastseries](http://npm.im/fastseries). If you need a fast work queue
|
||||
check out [fastq](http://npm.im/fastq). If you need to run fast
|
||||
waterfall calls, use [fastfall](http://npm.im/fastfall).
|
||||
|
||||
[](https://github.com/feross/standard)
|
||||
|
||||
__The major difference between version 1.x.x and 2.x.x is the order of
|
||||
results__, this is now ready to replace async in every case.
|
||||
|
||||
## Example for parallel call
|
||||
|
||||
```js
|
||||
var parallel = require('fastparallel')({
|
||||
// this is a function that will be called
|
||||
// when a parallel completes
|
||||
released: completed,
|
||||
|
||||
// if you want the results, then here you are
|
||||
results: true
|
||||
})
|
||||
|
||||
parallel(
|
||||
{}, // what will be this in the functions
|
||||
[something, something, something], // functions to call
|
||||
42, // the first argument of the functions
|
||||
done // the function to be called when the parallel ends
|
||||
)
|
||||
|
||||
function something (arg, cb) {
|
||||
setImmediate(cb, null, 'myresult')
|
||||
}
|
||||
|
||||
function done (err, results) {
|
||||
console.log('parallel completed, results:', results)
|
||||
}
|
||||
|
||||
function completed () {
|
||||
console.log('parallel completed!')
|
||||
}
|
||||
```
|
||||
|
||||
## Example for each and map calls
|
||||
|
||||
```js
|
||||
var parallel = require('fastparallel')({
|
||||
// this is a function that will be called
|
||||
// when a parallel completes
|
||||
released: completed,
|
||||
|
||||
// if you want the results, then here you are
|
||||
// passing false disables map
|
||||
results: true
|
||||
})
|
||||
|
||||
parallel(
|
||||
{}, // what will be this in the functions
|
||||
something, // functions to call
|
||||
[1, 2, 3], // the first argument of the functions
|
||||
done // the function to be called when the parallel ends
|
||||
)
|
||||
|
||||
function something (arg, cb) {
|
||||
setImmediate(cb, null, 'myresult')
|
||||
}
|
||||
|
||||
function done (err, results) {
|
||||
console.log('parallel completed, results:', results)
|
||||
}
|
||||
|
||||
function completed () {
|
||||
console.log('parallel completed!')
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Caveats
|
||||
|
||||
The `done` function will be called only once, even if more than one error happen.
|
||||
|
||||
This library works by caching the latest used function, so that running a new parallel
|
||||
does not cause **any memory allocations**.
|
||||
|
||||
## Why it is so fast?
|
||||
|
||||
1. This library is caching functions a lot.
|
||||
|
||||
2. V8 optimizations: thanks to caching, the functions can be optimized by V8 (if they are optimizable, and I took great care of making them so).
|
||||
|
||||
3. Don't use arrays if you just need a queue. A linked list implemented via processes is much faster if you don't need to access elements in between.
|
||||
|
||||
4. Accept passing a this for the functions. Thanks to this hack, you can extract your functions, and place them in a outer level where they are not created at every execution.
|
||||
|
||||
## License
|
||||
|
||||
ISC
|
||||
120
backend/node_modules/fastparallel/bench.js
generated
vendored
Normal file
120
backend/node_modules/fastparallel/bench.js
generated
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
var max = 1000000
|
||||
var parallel = require('./')()
|
||||
var parallelNoResults = require('./')({ results: false })
|
||||
var bench = require('fastbench')
|
||||
var async = require('async')
|
||||
var neo = require('neo-async')
|
||||
var insync = require('insync')
|
||||
var items = require('items')
|
||||
var parallelize = require('parallelize')
|
||||
|
||||
function benchFastParallel (done) {
|
||||
parallel(null, [somethingP, somethingP, somethingP], 42, done)
|
||||
}
|
||||
|
||||
function benchFastParallelNoResults (done) {
|
||||
parallelNoResults(null, [somethingP, somethingP, somethingP], 42, done)
|
||||
}
|
||||
|
||||
function benchFastParallelEach (done) {
|
||||
parallelNoResults(null, somethingP, [1, 2, 3], done)
|
||||
}
|
||||
|
||||
function benchFastParallelEachResults (done) {
|
||||
parallel(null, somethingP, [1, 2, 3], done)
|
||||
}
|
||||
|
||||
function benchAsyncParallel (done) {
|
||||
async.parallel([somethingA, somethingA, somethingA], done)
|
||||
}
|
||||
|
||||
function benchInsyncParallel (done) {
|
||||
insync.parallel([somethingA, somethingA, somethingA], done)
|
||||
}
|
||||
|
||||
function benchNeoParallel (done) {
|
||||
neo.parallel([somethingA, somethingA, somethingA], done)
|
||||
}
|
||||
|
||||
function benchItemsParallel (done) {
|
||||
items.parallel.execute([somethingA, somethingA, somethingA], done)
|
||||
}
|
||||
|
||||
function benchParallelize (done) {
|
||||
var next = parallelize(done)
|
||||
|
||||
somethingA(next())
|
||||
somethingA(next())
|
||||
somethingA(next())
|
||||
}
|
||||
|
||||
function benchAsyncEach (done) {
|
||||
async.each([1, 2, 3], somethingP, done)
|
||||
}
|
||||
|
||||
function benchNeoEach (done) {
|
||||
neo.each([1, 2, 3], somethingP, done)
|
||||
}
|
||||
|
||||
function benchAsyncMap (done) {
|
||||
async.map([1, 2, 3], somethingP, done)
|
||||
}
|
||||
|
||||
function benchNeoMap (done) {
|
||||
neo.map([1, 2, 3], somethingP, done)
|
||||
}
|
||||
|
||||
function benchInsyncEach (done) {
|
||||
insync.each([1, 2, 3], somethingP, done)
|
||||
}
|
||||
|
||||
function benchInsyncMap (done) {
|
||||
insync.map([1, 2, 3], somethingP, done)
|
||||
}
|
||||
|
||||
var nextDone
|
||||
var nextCount
|
||||
|
||||
function benchSetImmediate (done) {
|
||||
nextCount = 3
|
||||
nextDone = done
|
||||
setImmediate(somethingImmediate)
|
||||
setImmediate(somethingImmediate)
|
||||
setImmediate(somethingImmediate)
|
||||
}
|
||||
|
||||
function somethingImmediate () {
|
||||
nextCount--
|
||||
if (nextCount === 0) {
|
||||
nextDone()
|
||||
}
|
||||
}
|
||||
|
||||
function somethingP (arg, cb) {
|
||||
setImmediate(cb)
|
||||
}
|
||||
|
||||
function somethingA (cb) {
|
||||
setImmediate(cb)
|
||||
}
|
||||
|
||||
var run = bench([
|
||||
benchSetImmediate,
|
||||
benchAsyncParallel,
|
||||
benchAsyncEach,
|
||||
benchAsyncMap,
|
||||
benchNeoParallel,
|
||||
benchNeoEach,
|
||||
benchNeoMap,
|
||||
benchInsyncParallel,
|
||||
benchInsyncEach,
|
||||
benchInsyncMap,
|
||||
benchItemsParallel,
|
||||
benchParallelize,
|
||||
benchFastParallel,
|
||||
benchFastParallelNoResults,
|
||||
benchFastParallelEachResults,
|
||||
benchFastParallelEach
|
||||
], max)
|
||||
|
||||
run(run)
|
||||
41
backend/node_modules/fastparallel/bench_long.js
generated
vendored
Normal file
41
backend/node_modules/fastparallel/bench_long.js
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
var max = 1000000
|
||||
var parallel = require('./')()
|
||||
var parallelNoResults = require('./')({ results: false })
|
||||
var bench = require('fastbench')
|
||||
var async = require('async')
|
||||
var neo = require('neo-async')
|
||||
|
||||
var funcs = []
|
||||
|
||||
for (var i = 0; i < 25; i++) {
|
||||
funcs.push(something)
|
||||
}
|
||||
|
||||
function benchFastParallel (done) {
|
||||
parallel(null, funcs, 42, done)
|
||||
}
|
||||
|
||||
function benchFastParallelNoResults (done) {
|
||||
parallelNoResults(null, funcs, 42, done)
|
||||
}
|
||||
|
||||
function benchAsyncParallel (done) {
|
||||
async.parallel(funcs, done)
|
||||
}
|
||||
|
||||
function benchNeoParallel (done) {
|
||||
neo.parallel(funcs, done)
|
||||
}
|
||||
|
||||
function something (cb) {
|
||||
setImmediate(cb)
|
||||
}
|
||||
|
||||
var run = bench([
|
||||
benchAsyncParallel,
|
||||
benchNeoParallel,
|
||||
benchFastParallel,
|
||||
benchFastParallelNoResults
|
||||
], max)
|
||||
|
||||
run(run)
|
||||
40
backend/node_modules/fastparallel/example.js
generated
vendored
Normal file
40
backend/node_modules/fastparallel/example.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
var parallel = require('./')({
|
||||
// this is a function that will be called
|
||||
// when a parallel completes
|
||||
released: completed,
|
||||
|
||||
// we want results and errors
|
||||
// passing false will make it faster!
|
||||
results: true
|
||||
})
|
||||
|
||||
parallel(
|
||||
{}, // what will be this in the functions
|
||||
[something, something, something], // functions to call
|
||||
42, // the first argument of the functions
|
||||
next // the function to be called when the parallel ends
|
||||
)
|
||||
|
||||
function something (arg, cb) {
|
||||
setImmediate(cb, null, 'myresult')
|
||||
}
|
||||
|
||||
function next (err, results) {
|
||||
if (err) {
|
||||
// do something here!
|
||||
}
|
||||
console.log('parallel completed, results:', results)
|
||||
|
||||
parallel({}, something, [1, 2, 3], done)
|
||||
}
|
||||
|
||||
function done (err, results) {
|
||||
if (err) {
|
||||
// do something here!
|
||||
}
|
||||
console.log('parallel completed, results:', results)
|
||||
}
|
||||
|
||||
function completed () {
|
||||
console.log('parallel completed!')
|
||||
}
|
||||
48
backend/node_modules/fastparallel/package.json
generated
vendored
Normal file
48
backend/node_modules/fastparallel/package.json
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"name": "fastparallel",
|
||||
"version": "2.4.1",
|
||||
"description": "Zero-overhead asynchronous parallel/each/map function call",
|
||||
"main": "parallel.js",
|
||||
"scripts": {
|
||||
"lint": "standard",
|
||||
"test": "tape test.js | faucet",
|
||||
"coverage": "nyc --reporter=lcov tape test.js; cat coverage/lcov.info | coveralls"
|
||||
},
|
||||
"pre-commit": [
|
||||
"lint",
|
||||
"test"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mcollina/fastparallel.git"
|
||||
},
|
||||
"keywords": [
|
||||
"parallel",
|
||||
"fast",
|
||||
"async"
|
||||
],
|
||||
"author": "Matteo Collina <hello@matteocollina.com>",
|
||||
"license": "ISC",
|
||||
"bugs": {
|
||||
"url": "https://github.com/mcollina/fastparallel/issues"
|
||||
},
|
||||
"homepage": "https://github.com/mcollina/fastparallel",
|
||||
"devDependencies": {
|
||||
"async": "^3.1.0",
|
||||
"coveralls": "^3.0.5",
|
||||
"fastbench": "^1.0.1",
|
||||
"faucet": "0.0.1",
|
||||
"insync": "^2.1.1",
|
||||
"items": "^2.1.2",
|
||||
"neo-async": "^2.6.1",
|
||||
"nyc": "^14.1.1",
|
||||
"parallelize": "^3.0.1",
|
||||
"pre-commit": "^1.2.2",
|
||||
"standard": "^13.0.1",
|
||||
"tape": "^4.11.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"reusify": "^1.0.4",
|
||||
"xtend": "^4.0.2"
|
||||
}
|
||||
}
|
||||
199
backend/node_modules/fastparallel/parallel.js
generated
vendored
Normal file
199
backend/node_modules/fastparallel/parallel.js
generated
vendored
Normal file
@@ -0,0 +1,199 @@
|
||||
'use strict'
|
||||
|
||||
var xtend = require('xtend')
|
||||
var reusify = require('reusify')
|
||||
var defaults = {
|
||||
released: nop,
|
||||
results: true
|
||||
}
|
||||
|
||||
function fastparallel (options) {
|
||||
options = xtend(defaults, options)
|
||||
|
||||
var released = options.released
|
||||
var queue = reusify(options.results ? ResultsHolder : NoResultsHolder)
|
||||
var queueSingleCaller = reusify(SingleCaller)
|
||||
var goArray = options.results ? goResultsArray : goNoResultsArray
|
||||
var goFunc = options.results ? goResultsFunc : goNoResultsFunc
|
||||
|
||||
return parallel
|
||||
|
||||
function parallel (that, toCall, arg, done) {
|
||||
var holder = queue.get()
|
||||
done = done || nop
|
||||
if (toCall.length === 0) {
|
||||
done.call(that)
|
||||
released(holder)
|
||||
} else {
|
||||
holder._callback = done
|
||||
holder._callThat = that
|
||||
holder._release = release
|
||||
|
||||
if (typeof toCall === 'function') {
|
||||
goFunc(that, toCall, arg, holder)
|
||||
} else {
|
||||
goArray(that, toCall, arg, holder)
|
||||
}
|
||||
|
||||
if (holder._count === 0) {
|
||||
holder.release()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function release (holder) {
|
||||
queue.release(holder)
|
||||
released(holder)
|
||||
}
|
||||
|
||||
function singleCallerRelease (holder) {
|
||||
queueSingleCaller.release(holder)
|
||||
}
|
||||
|
||||
function goResultsFunc (that, toCall, arg, holder) {
|
||||
var singleCaller = null
|
||||
holder._count = arg.length
|
||||
holder._results = new Array(holder._count)
|
||||
for (var i = 0; i < arg.length; i++) {
|
||||
singleCaller = queueSingleCaller.get()
|
||||
singleCaller._release = singleCallerRelease
|
||||
singleCaller.parent = holder
|
||||
singleCaller.pos = i
|
||||
if (that) {
|
||||
toCall.call(that, arg[i], singleCaller.release)
|
||||
} else {
|
||||
toCall(arg[i], singleCaller.release)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function goResultsArray (that, funcs, arg, holder) {
|
||||
var sc = null
|
||||
var tc = nop
|
||||
holder._count = funcs.length
|
||||
holder._results = new Array(holder._count)
|
||||
for (var i = 0; i < funcs.length; i++) {
|
||||
sc = queueSingleCaller.get()
|
||||
sc._release = singleCallerRelease
|
||||
sc.parent = holder
|
||||
sc.pos = i
|
||||
tc = funcs[i]
|
||||
if (that) {
|
||||
if (tc.length === 1) tc.call(that, sc.release)
|
||||
else tc.call(that, arg, sc.release)
|
||||
} else {
|
||||
if (tc.length === 1) tc(sc.release)
|
||||
else tc(arg, sc.release)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function goNoResultsFunc (that, toCall, arg, holder) {
|
||||
holder._count = arg.length
|
||||
for (var i = 0; i < arg.length; i++) {
|
||||
if (that) {
|
||||
toCall.call(that, arg[i], holder.release)
|
||||
} else {
|
||||
toCall(arg[i], holder.release)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function goNoResultsArray (that, funcs, arg, holder) {
|
||||
var toCall = null
|
||||
holder._count = funcs.length
|
||||
for (var i = 0; i < funcs.length; i++) {
|
||||
toCall = funcs[i]
|
||||
if (that) {
|
||||
if (toCall.length === 1) {
|
||||
toCall.call(that, holder.release)
|
||||
} else {
|
||||
toCall.call(that, arg, holder.release)
|
||||
}
|
||||
} else {
|
||||
if (toCall.length === 1) {
|
||||
toCall(holder.release)
|
||||
} else {
|
||||
toCall(arg, holder.release)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function NoResultsHolder () {
|
||||
this._count = -1
|
||||
this._callback = nop
|
||||
this._callThat = null
|
||||
this._release = null
|
||||
this.next = null
|
||||
|
||||
var that = this
|
||||
var i = 0
|
||||
this.release = function () {
|
||||
var cb = that._callback
|
||||
if (++i === that._count || that._count === 0) {
|
||||
if (that._callThat) {
|
||||
cb.call(that._callThat)
|
||||
} else {
|
||||
cb()
|
||||
}
|
||||
that._callback = nop
|
||||
that._callThat = null
|
||||
i = 0
|
||||
that._release(that)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function SingleCaller () {
|
||||
this.pos = -1
|
||||
this._release = nop
|
||||
this.parent = null
|
||||
this.next = null
|
||||
|
||||
var that = this
|
||||
this.release = function (err, result) {
|
||||
that.parent.release(err, that.pos, result)
|
||||
that.pos = -1
|
||||
that.parent = null
|
||||
that._release(that)
|
||||
}
|
||||
}
|
||||
|
||||
function ResultsHolder () {
|
||||
this._count = -1
|
||||
this._callback = nop
|
||||
this._results = null
|
||||
this._err = null
|
||||
this._callThat = null
|
||||
this._release = nop
|
||||
this.next = null
|
||||
|
||||
var that = this
|
||||
var i = 0
|
||||
this.release = function (err, pos, result) {
|
||||
that._err = that._err || err
|
||||
if (pos >= 0) {
|
||||
that._results[pos] = result
|
||||
}
|
||||
var cb = that._callback
|
||||
if (++i === that._count || that._count === 0) {
|
||||
if (that._callThat) {
|
||||
cb.call(that._callThat, that._err, that._results)
|
||||
} else {
|
||||
cb(that._err, that._results)
|
||||
}
|
||||
that._callback = nop
|
||||
that._results = null
|
||||
that._err = null
|
||||
that._callThat = null
|
||||
i = 0
|
||||
that._release(that)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function nop () { }
|
||||
|
||||
module.exports = fastparallel
|
||||
465
backend/node_modules/fastparallel/test.js
generated
vendored
Normal file
465
backend/node_modules/fastparallel/test.js
generated
vendored
Normal file
@@ -0,0 +1,465 @@
|
||||
var test = require('tape')
|
||||
var parallel = require('./')
|
||||
|
||||
test('basically works', function (t) {
|
||||
t.plan(6)
|
||||
|
||||
var instance = parallel({
|
||||
released: released
|
||||
})
|
||||
var count = 0
|
||||
var obj = {}
|
||||
|
||||
instance(obj, [something, something], 42, function done () {
|
||||
t.equal(count, 2, 'all functions must have completed')
|
||||
})
|
||||
|
||||
function something (arg, cb) {
|
||||
t.equal(obj, this)
|
||||
t.equal(arg, 42)
|
||||
setImmediate(function () {
|
||||
count++
|
||||
cb()
|
||||
})
|
||||
}
|
||||
|
||||
function released () {
|
||||
t.pass('release')
|
||||
}
|
||||
})
|
||||
|
||||
test('accumulates results', function (t) {
|
||||
t.plan(8)
|
||||
|
||||
var instance = parallel({
|
||||
released: released
|
||||
})
|
||||
var count = 0
|
||||
var obj = {}
|
||||
|
||||
instance(obj, [something, something], 42, function done (err, results) {
|
||||
t.notOk(err, 'no error')
|
||||
t.equal(count, 2, 'all functions must have completed')
|
||||
t.deepEqual(results, [1, 2])
|
||||
})
|
||||
|
||||
function something (arg, cb) {
|
||||
t.equal(obj, this)
|
||||
t.equal(arg, 42)
|
||||
setImmediate(function () {
|
||||
count++
|
||||
cb(null, count)
|
||||
})
|
||||
}
|
||||
|
||||
function released () {
|
||||
t.pass()
|
||||
}
|
||||
})
|
||||
|
||||
test('fowards errs', function (t) {
|
||||
t.plan(3)
|
||||
|
||||
var instance = parallel({
|
||||
released: released
|
||||
})
|
||||
var count = 0
|
||||
var obj = {}
|
||||
|
||||
instance(obj, [somethingErr, something], 42, function done (err, results) {
|
||||
t.ok(err)
|
||||
t.equal(count, 2, 'all functions must have completed')
|
||||
})
|
||||
|
||||
function something (arg, cb) {
|
||||
setImmediate(function () {
|
||||
count++
|
||||
cb(null, count)
|
||||
})
|
||||
}
|
||||
|
||||
function somethingErr (arg, cb) {
|
||||
setImmediate(function () {
|
||||
count++
|
||||
cb(new Error('this is an err!'))
|
||||
})
|
||||
}
|
||||
|
||||
function released () {
|
||||
t.pass()
|
||||
}
|
||||
})
|
||||
|
||||
test('fowards errs (bis)', function (t) {
|
||||
t.plan(3)
|
||||
|
||||
var instance = parallel({
|
||||
released: released
|
||||
})
|
||||
var count = 0
|
||||
var obj = {}
|
||||
|
||||
instance(obj, [something, somethingErr], 42, function done (err, results) {
|
||||
t.ok(err)
|
||||
t.equal(count, 2, 'all functions must have completed')
|
||||
})
|
||||
|
||||
function something (arg, cb) {
|
||||
setImmediate(function () {
|
||||
count++
|
||||
cb(null, count)
|
||||
})
|
||||
}
|
||||
|
||||
function somethingErr (arg, cb) {
|
||||
setImmediate(function () {
|
||||
count++
|
||||
cb(new Error('this is an err!'))
|
||||
})
|
||||
}
|
||||
|
||||
function released () {
|
||||
t.pass()
|
||||
}
|
||||
})
|
||||
|
||||
test('does not forward errors or result with results:false flag', function (t) {
|
||||
t.plan(8)
|
||||
|
||||
var instance = parallel({
|
||||
released: released,
|
||||
results: false
|
||||
})
|
||||
var count = 0
|
||||
var obj = {}
|
||||
|
||||
instance(obj, [something, something], 42, function done (err, results) {
|
||||
t.equal(err, undefined, 'no err')
|
||||
t.equal(results, undefined, 'no err')
|
||||
t.equal(count, 2, 'all functions must have completed')
|
||||
})
|
||||
|
||||
function something (arg, cb) {
|
||||
t.equal(obj, this)
|
||||
t.equal(arg, 42)
|
||||
setImmediate(function () {
|
||||
count++
|
||||
cb()
|
||||
})
|
||||
}
|
||||
|
||||
function released () {
|
||||
t.pass()
|
||||
}
|
||||
})
|
||||
|
||||
test('should call done and released if an empty is passed', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
var instance = parallel({
|
||||
released: released
|
||||
})
|
||||
var obj = {}
|
||||
|
||||
instance(obj, [], 42, function done () {
|
||||
t.pass()
|
||||
})
|
||||
|
||||
function released () {
|
||||
t.pass()
|
||||
}
|
||||
})
|
||||
|
||||
test('each support', function (t) {
|
||||
t.plan(8)
|
||||
|
||||
var instance = parallel({
|
||||
released: released
|
||||
})
|
||||
var count = 0
|
||||
var obj = {}
|
||||
var args = [1, 2, 3]
|
||||
var i = 0
|
||||
|
||||
instance(obj, something, args, function done () {
|
||||
t.equal(count, 3, 'all functions must have completed')
|
||||
})
|
||||
|
||||
function something (arg, cb) {
|
||||
t.equal(obj, this, 'this matches')
|
||||
t.equal(args[i++], arg, 'the arg is correct')
|
||||
setImmediate(function () {
|
||||
count++
|
||||
cb()
|
||||
})
|
||||
}
|
||||
|
||||
function released () {
|
||||
t.pass()
|
||||
}
|
||||
})
|
||||
|
||||
test('call the callback with the given this', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
var instance = parallel()
|
||||
var obj = {}
|
||||
|
||||
instance(obj, [build(), build()], 42, function done () {
|
||||
t.equal(obj, this, 'this matches')
|
||||
})
|
||||
|
||||
function build () {
|
||||
return function something (arg, cb) {
|
||||
setImmediate(cb)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
test('call the callback with the given this with no results', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
var instance = parallel({ results: false })
|
||||
var obj = {}
|
||||
|
||||
instance(obj, [build(), build()], 42, function done () {
|
||||
t.equal(obj, this, 'this matches')
|
||||
})
|
||||
|
||||
function build () {
|
||||
return function something (arg, cb) {
|
||||
setImmediate(cb)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
test('call the callback with the given this with no data', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
var instance = parallel()
|
||||
var obj = {}
|
||||
|
||||
instance(obj, [], 42, function done () {
|
||||
t.equal(obj, this, 'this matches')
|
||||
})
|
||||
})
|
||||
|
||||
test('call the result callback when the each array is empty', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
var instance = parallel()
|
||||
var obj = {}
|
||||
|
||||
instance(obj, something, [], function done () {
|
||||
t.pass('the result function has been called')
|
||||
})
|
||||
|
||||
function something (arg, cb) {
|
||||
t.error('this should never be called')
|
||||
}
|
||||
})
|
||||
|
||||
test('call the result callback when the each array is empty with no results', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
var instance = parallel({ results: false })
|
||||
var obj = {}
|
||||
|
||||
instance(obj, something, [], function done () {
|
||||
t.pass('the result function has been called')
|
||||
})
|
||||
|
||||
function something (arg, cb) {
|
||||
t.error('this should never be called')
|
||||
}
|
||||
})
|
||||
|
||||
test('does not require a done callback', function (t) {
|
||||
t.plan(4)
|
||||
|
||||
var instance = parallel()
|
||||
var obj = {}
|
||||
|
||||
instance(obj, [something, something], 42)
|
||||
|
||||
function something (arg, cb) {
|
||||
t.equal(obj, this)
|
||||
t.equal(arg, 42)
|
||||
setImmediate(cb)
|
||||
}
|
||||
})
|
||||
|
||||
test('works with sync functions with no results', function (t) {
|
||||
t.plan(6)
|
||||
|
||||
var instance = parallel({
|
||||
results: false,
|
||||
released: released
|
||||
})
|
||||
var count = 0
|
||||
var obj = {}
|
||||
|
||||
instance(obj, [something, something], 42, function done () {
|
||||
t.equal(2, count, 'all functions must have completed')
|
||||
})
|
||||
|
||||
function something (arg, cb) {
|
||||
t.equal(this, obj)
|
||||
t.equal(42, arg)
|
||||
count++
|
||||
cb()
|
||||
}
|
||||
|
||||
function released () {
|
||||
t.pass('release')
|
||||
}
|
||||
})
|
||||
|
||||
test('accumulates results in order', function (t) {
|
||||
t.plan(8)
|
||||
|
||||
var instance = parallel({
|
||||
released: released
|
||||
})
|
||||
var count = 2
|
||||
var obj = {}
|
||||
|
||||
instance(obj, [something, something], 42, function done (err, results) {
|
||||
t.notOk(err, 'no error')
|
||||
t.equal(count, 0, 'all functions must have completed')
|
||||
t.deepEqual(results, [2, 1])
|
||||
})
|
||||
|
||||
function something (arg, cb) {
|
||||
t.equal(obj, this)
|
||||
t.equal(arg, 42)
|
||||
var value = count--
|
||||
setTimeout(function () {
|
||||
cb(null, value)
|
||||
}, 10 * value)
|
||||
}
|
||||
|
||||
function released () {
|
||||
t.pass()
|
||||
}
|
||||
})
|
||||
|
||||
test('call without arg if there is no arg with no results', function (t) {
|
||||
t.plan(3)
|
||||
|
||||
var instance = parallel({
|
||||
results: false
|
||||
})
|
||||
var count = 0
|
||||
var obj = {}
|
||||
|
||||
instance(obj, [something, something], 42, function done () {
|
||||
t.equal(count, 2, 'all functions must have completed')
|
||||
})
|
||||
|
||||
function something (cb) {
|
||||
t.equal(obj, this)
|
||||
setImmediate(function () {
|
||||
count++
|
||||
cb()
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
test('call without arg if there is no arg with results', function (t) {
|
||||
t.plan(3)
|
||||
|
||||
var instance = parallel()
|
||||
var count = 0
|
||||
var obj = {}
|
||||
|
||||
instance(obj, [something, something], 42, function done () {
|
||||
t.equal(count, 2, 'all functions must have completed')
|
||||
})
|
||||
|
||||
function something (cb) {
|
||||
t.equal(obj, this)
|
||||
setImmediate(function () {
|
||||
count++
|
||||
cb()
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
test('each support with nothing to process', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
var instance = parallel()
|
||||
var obj = {}
|
||||
var args = []
|
||||
|
||||
instance(obj, something, args, function done (err, results) {
|
||||
t.error(err)
|
||||
t.deepEqual(results, [], 'empty results')
|
||||
})
|
||||
|
||||
function something (arg, cb) {
|
||||
t.fail('this should never happen')
|
||||
}
|
||||
})
|
||||
|
||||
test('each without results support with nothing to process', function (t) {
|
||||
t.plan(1)
|
||||
|
||||
var instance = parallel({ results: false })
|
||||
var obj = {}
|
||||
var args = []
|
||||
|
||||
instance(obj, something, args, function done () {
|
||||
t.pass('done called')
|
||||
})
|
||||
|
||||
function something (arg, cb) {
|
||||
t.fail('this should never happen')
|
||||
}
|
||||
})
|
||||
|
||||
test('each works with arrays of objects', function (t) {
|
||||
t.plan(3)
|
||||
|
||||
var instance = parallel({ results: false })
|
||||
var obj = {}
|
||||
var args = [{ val: true }, { val: true }]
|
||||
|
||||
instance(obj, something, args, function () {
|
||||
t.ok('done called')
|
||||
})
|
||||
|
||||
function something (arg, cb) {
|
||||
t.ok(arg.val)
|
||||
cb()
|
||||
}
|
||||
})
|
||||
|
||||
test('using same instance multiple times clears the state of result holder', function (t) {
|
||||
var total = 10
|
||||
t.plan(total)
|
||||
|
||||
var instance = parallel({
|
||||
results: false,
|
||||
released: released
|
||||
})
|
||||
var obj = {}
|
||||
var count = 0
|
||||
|
||||
function released () {
|
||||
if (count < total) {
|
||||
instance(obj, [something], 42, function done () {
|
||||
t.ok(true, 'done is called')
|
||||
count++
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
released()
|
||||
function something (cb) {
|
||||
setImmediate(function () {
|
||||
cb()
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user