Projektstart
This commit is contained in:
27
backend/node_modules/fastfall/.npmignore
generated
vendored
Normal file
27
backend/node_modules/fastfall/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directory
|
||||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
|
||||
node_modules
|
||||
16
backend/node_modules/fastfall/.travis.yml
generated
vendored
Normal file
16
backend/node_modules/fastfall/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
sudo: false
|
||||
language: node_js
|
||||
|
||||
node_js:
|
||||
- "0.10"
|
||||
- "0.12"
|
||||
- "iojs"
|
||||
- "4"
|
||||
- "5"
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- node_modules
|
||||
|
||||
after_script:
|
||||
npm run coveralls
|
||||
22
backend/node_modules/fastfall/LICENSE
generated
vendored
Normal file
22
backend/node_modules/fastfall/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Matteo Collina
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
232
backend/node_modules/fastfall/README.md
generated
vendored
Normal file
232
backend/node_modules/fastfall/README.md
generated
vendored
Normal file
@@ -0,0 +1,232 @@
|
||||
# fastfall
|
||||
|
||||
[![npm version][npm-badge]][npm-url]
|
||||
[![Build Status][travis-badge]][travis-url]
|
||||
[![Coverage Status][coveralls-badge]][coveralls-url]
|
||||
[![Dependency Status][david-badge]][david-url]
|
||||
|
||||
## call your callbacks in a waterfall, without overhead
|
||||
|
||||
Benchmark for doing 3 calls `setImmediate` 100 thousands times:
|
||||
|
||||
* non-reusable setImmediate: 407ms
|
||||
* [async.waterfall](https://github.com/caolan/async#waterfall): 1203ms
|
||||
* [run-waterfall](http://npm.im/run-waterfall): 1432ms
|
||||
* [insync.wasterfall](https://www.npmjs.com/package/insync#waterfall):
|
||||
1570ms
|
||||
* [neo-async.wasterfall](http://suguru03.github.io/neo-async/doc/async.waterfall.html):
|
||||
445ms
|
||||
* [waterfallize](http://npm.im/waterfallize): 757ms
|
||||
* `fastfall`: 432ms
|
||||
* `fastfall` compiled: 428ms
|
||||
|
||||
|
||||
These benchmarks where taken via `bench.js` on node 4.2.2, on a MacBook
|
||||
Pro Retina 2014 (i7, 16GB of RAM).
|
||||
|
||||
If you need zero-overhead series function call, check out
|
||||
[fastseries](http://npm.im/fastseries), for parallel calls check out
|
||||
[fastparallel](http://npm.im/fastparallel), and for a fast work queue
|
||||
use [fastq](http://npm.im/fastq).
|
||||
|
||||
[](https://github.com/feross/standard)
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
npm install fastfall --save
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
var fall = require('fastfall')()
|
||||
|
||||
fall([
|
||||
function a (cb) {
|
||||
console.log('called a')
|
||||
cb(null, 'a')
|
||||
},
|
||||
function b (a, cb) {
|
||||
console.log('called b with:', a)
|
||||
cb(null, 'a', 'b')
|
||||
},
|
||||
function c (a, b, cb) {
|
||||
console.log('called c with:', a, b)
|
||||
cb(null, 'a', 'b', 'c')
|
||||
}], function result (err, a, b, c) {
|
||||
console.log('result arguments', arguments)
|
||||
})
|
||||
```
|
||||
|
||||
You can also set `this` when you create a fall:
|
||||
|
||||
```js
|
||||
var that = { hello: 'world' }
|
||||
var fall = require('fastfall')(that)
|
||||
|
||||
fall([a, b, c], result)
|
||||
|
||||
function a (cb) {
|
||||
console.log(this)
|
||||
console.log('called a')
|
||||
cb(null, 'a')
|
||||
}
|
||||
|
||||
function b (a, cb) {
|
||||
console.log('called b with:', a)
|
||||
cb(null, 'a', 'b')
|
||||
}
|
||||
|
||||
function c (a, b, cb) {
|
||||
console.log('called c with:', a, b)
|
||||
cb(null, 'a', 'b', 'c')
|
||||
}
|
||||
|
||||
function result (err, a, b, c) {
|
||||
console.log('result arguments', arguments)
|
||||
}
|
||||
```
|
||||
|
||||
You can also set `this` when you run a task:
|
||||
|
||||
```js
|
||||
var that = { hello: 'world' }
|
||||
var fall = require('fastfall')()
|
||||
|
||||
fall(new State('world'), [
|
||||
a, b, c,
|
||||
], console.log)
|
||||
|
||||
function State (value) {
|
||||
this.value = value
|
||||
}
|
||||
|
||||
function a (cb) {
|
||||
console.log(this.value)
|
||||
console.log('called a')
|
||||
cb(null, 'a')
|
||||
}
|
||||
|
||||
function b (a, cb) {
|
||||
console.log('called b with:', a)
|
||||
cb(null, 'a', 'b')
|
||||
}
|
||||
|
||||
function c (a, b, cb) {
|
||||
console.log('called c with:', a, b)
|
||||
cb(null, 'a', 'b', 'c')
|
||||
}
|
||||
```
|
||||
|
||||
### Compile a waterfall
|
||||
|
||||
```js
|
||||
var fall = require('fastfall')([
|
||||
function a (arg, cb) {
|
||||
console.log('called a')
|
||||
cb(null, arg)
|
||||
},
|
||||
function b (a, cb) {
|
||||
console.log('called b with:', a)
|
||||
cb(null, 'a', 'b')
|
||||
},
|
||||
function c (a, b, cb) {
|
||||
console.log('called c with:', a, b)
|
||||
cb(null, 'a', 'b', 'c')
|
||||
}])
|
||||
|
||||
// a compiled fall supports arguments too!
|
||||
fall(42, function result (err, a, b, c) {
|
||||
console.log('result arguments', arguments)
|
||||
})
|
||||
```
|
||||
|
||||
You can set `this` by doing:
|
||||
|
||||
```js
|
||||
var that = { hello: 'world' }
|
||||
var fall = require('fastfall')(that, [
|
||||
function a (arg, cb) {
|
||||
console.log('this is', this)
|
||||
console.log('called a')
|
||||
cb(null, arg)
|
||||
},
|
||||
function b (a, cb) {
|
||||
console.log('called b with:', a)
|
||||
cb(null, 'a', 'b')
|
||||
},
|
||||
function c (a, b, cb) {
|
||||
console.log('called c with:', a, b)
|
||||
cb(null, 'a', 'b', 'c')
|
||||
}])
|
||||
|
||||
// a compiled fall supports arguments too!
|
||||
fall(42, function result (err, a, b, c) {
|
||||
console.log('result arguments', arguments)
|
||||
})
|
||||
```
|
||||
|
||||
or you can simply attach it to an object:
|
||||
|
||||
```js
|
||||
var that = { hello: 'world' }
|
||||
that.doSomething = require('fastfall')([
|
||||
function a (arg, cb) {
|
||||
console.log('this is', this)
|
||||
console.log('called a')
|
||||
cb(null, arg)
|
||||
},
|
||||
function b (a, cb) {
|
||||
console.log('called b with:', a)
|
||||
cb(null, 'a', 'b')
|
||||
},
|
||||
function c (a, b, cb) {
|
||||
console.log('called c with:', a, b)
|
||||
cb(null, 'a', 'b', 'c')
|
||||
}])
|
||||
|
||||
// a compiled fall supports arguments too!
|
||||
that.doSomething(42, function result (err, a, b, c) {
|
||||
console.log('this is', this)
|
||||
console.log('result arguments', arguments)
|
||||
})
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### fastfall([this], [functions])
|
||||
|
||||
Creates a `fall`, it can either be pre-filled with a `this` value
|
||||
and an array of functions.
|
||||
|
||||
If there is no list of functions, [a not-compiled fall](#not-compiled)
|
||||
is returned, if there is a list of function [a compiled fall](#compiled)
|
||||
is returned.
|
||||
|
||||
<a name="not-compiled"></a>
|
||||
### fall([this], functions, [done])
|
||||
|
||||
Calls the functions in a waterfall, forwarding the arguments from one to
|
||||
another. Calls `done` when it has finished.
|
||||
|
||||
<a name="compiled"></a>
|
||||
### fall(args..., [done])
|
||||
|
||||
Calls the compiled functions in a waterfall, forwarding the arguments from one to
|
||||
another. Additionally, a user can specify some arguments for the first
|
||||
function, too. Calls `done` when it has finished.
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
|
||||
[npm-badge]: https://badge.fury.io/js/fastfall.svg
|
||||
[npm-url]: https://badge.fury.io/js/fastfall
|
||||
[travis-badge]: https://api.travis-ci.org/mcollina/fastfall.svg
|
||||
[travis-url]: https://travis-ci.org/mcollina/fastfall
|
||||
[coveralls-badge]:https://coveralls.io/repos/mcollina/fastfall/badge.svg?branch=master&service=github
|
||||
[coveralls-url]: https://coveralls.io/github/mcollina/fastfall?branch=master
|
||||
[david-badge]: https://david-dm.org/mcollina/fastfall.svg
|
||||
[david-url]: https://david-dm.org/mcollina/fastfall
|
||||
81
backend/node_modules/fastfall/bench.js
generated
vendored
Normal file
81
backend/node_modules/fastfall/bench.js
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
'use strict'
|
||||
|
||||
var max = 100000
|
||||
var async = require('async')
|
||||
var insync = require('insync')
|
||||
var neoAsync = require('neo-async')
|
||||
var fall = require('./')()
|
||||
var runWaterfall = require('run-waterfall')
|
||||
var waterfallize = require('waterfallize')
|
||||
var bench = require('fastbench')
|
||||
|
||||
var nextDone
|
||||
var nextCount
|
||||
|
||||
function benchSetImmediate (done) {
|
||||
nextCount = 3
|
||||
nextDone = done
|
||||
setImmediate(somethingImmediate)
|
||||
}
|
||||
|
||||
function somethingImmediate () {
|
||||
nextCount--
|
||||
if (nextCount === 0) {
|
||||
nextDone()
|
||||
} else {
|
||||
setImmediate(somethingImmediate)
|
||||
}
|
||||
}
|
||||
|
||||
function somethingB (cb) {
|
||||
setImmediate(cb)
|
||||
}
|
||||
|
||||
function somethingA (cb) {
|
||||
setImmediate(cb)
|
||||
}
|
||||
|
||||
var toCall = [somethingA, somethingB, somethingB]
|
||||
function benchAsyncWaterfall (done) {
|
||||
async.waterfall(toCall, done)
|
||||
}
|
||||
|
||||
function benchFastFall (done) {
|
||||
fall(toCall, done)
|
||||
}
|
||||
|
||||
function benchWaterfallize (done) {
|
||||
var next = waterfallize()
|
||||
|
||||
next(toCall[0])
|
||||
next(toCall[1])
|
||||
next(toCall[2])
|
||||
next(done)
|
||||
}
|
||||
|
||||
function benchRunWaterFall (done) {
|
||||
runWaterfall(toCall, done)
|
||||
}
|
||||
|
||||
function benchInsync (done) {
|
||||
insync.waterfall(toCall, done)
|
||||
}
|
||||
|
||||
function benchNeoAsync (done) {
|
||||
neoAsync.waterfall(toCall, done)
|
||||
}
|
||||
|
||||
var compiled = require('./')(toCall)
|
||||
|
||||
var run = bench([
|
||||
benchAsyncWaterfall,
|
||||
benchInsync,
|
||||
benchNeoAsync,
|
||||
benchRunWaterFall,
|
||||
benchSetImmediate,
|
||||
benchWaterfallize,
|
||||
benchFastFall,
|
||||
compiled
|
||||
], max)
|
||||
|
||||
run(run)
|
||||
20
backend/node_modules/fastfall/example.js
generated
vendored
Normal file
20
backend/node_modules/fastfall/example.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
'use strict'
|
||||
|
||||
var fall = require('./')()
|
||||
|
||||
fall([
|
||||
function a (cb) {
|
||||
console.log('called a')
|
||||
cb(null, 'a')
|
||||
},
|
||||
function b (a, cb) {
|
||||
console.log('called b with:', a)
|
||||
cb(null, 'a', 'b')
|
||||
},
|
||||
function c (a, b, cb) {
|
||||
console.log('called c with:', a, b)
|
||||
cb(null, 'a', 'b', 'c')
|
||||
}
|
||||
], function result (err, a, b, c) {
|
||||
console.log('result arguments', err, a, b, c)
|
||||
})
|
||||
150
backend/node_modules/fastfall/fall.js
generated
vendored
Normal file
150
backend/node_modules/fastfall/fall.js
generated
vendored
Normal file
@@ -0,0 +1,150 @@
|
||||
'use strict'
|
||||
|
||||
var reusify = require('reusify')
|
||||
var empty = []
|
||||
|
||||
function fastfall (context, template) {
|
||||
if (Array.isArray(context)) {
|
||||
template = context
|
||||
context = null
|
||||
}
|
||||
|
||||
var queue = reusify(Holder)
|
||||
|
||||
return template ? compiled : fall
|
||||
|
||||
function fall () {
|
||||
var current = queue.get()
|
||||
current.release = release
|
||||
|
||||
if (arguments.length === 3) {
|
||||
current.context = arguments[0]
|
||||
current.list = arguments[1]
|
||||
current.callback = arguments[2] || noop
|
||||
} else {
|
||||
current.context = context
|
||||
current.list = arguments[0]
|
||||
current.callback = arguments[1] || noop
|
||||
}
|
||||
|
||||
current.work()
|
||||
}
|
||||
|
||||
function release (holder) {
|
||||
queue.release(holder)
|
||||
}
|
||||
|
||||
function compiled () {
|
||||
var current = queue.get()
|
||||
current.release = release
|
||||
|
||||
current.list = template
|
||||
|
||||
var args
|
||||
var i
|
||||
var len = arguments.length - 1
|
||||
|
||||
current.context = this || context
|
||||
current.callback = arguments[len] || noop
|
||||
|
||||
switch (len) {
|
||||
case 0:
|
||||
current.work()
|
||||
break
|
||||
case 1:
|
||||
current.work(null, arguments[0])
|
||||
break
|
||||
case 2:
|
||||
current.work(null, arguments[0], arguments[1])
|
||||
break
|
||||
case 3:
|
||||
current.work(null, arguments[0], arguments[1], arguments[2])
|
||||
break
|
||||
case 4:
|
||||
current.work(null, arguments[0], arguments[1], arguments[2], arguments[3])
|
||||
break
|
||||
default:
|
||||
args = new Array(len + 1)
|
||||
args[0] = null
|
||||
for (i = 0; i < len; i++) {
|
||||
args[i + 1] = arguments[i]
|
||||
}
|
||||
current.work.apply(null, args)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function noop () {}
|
||||
|
||||
function Holder () {
|
||||
this.list = empty
|
||||
this.callback = noop
|
||||
this.count = 0
|
||||
this.context = undefined
|
||||
this.release = noop
|
||||
|
||||
var that = this
|
||||
|
||||
this.work = function work () {
|
||||
if (arguments.length > 0 && arguments[0]) {
|
||||
return that.callback.call(that.context, arguments[0])
|
||||
}
|
||||
|
||||
var len = arguments.length
|
||||
var i
|
||||
var args
|
||||
var func
|
||||
|
||||
if (that.count < that.list.length) {
|
||||
func = that.list[that.count++]
|
||||
switch (len) {
|
||||
case 0:
|
||||
case 1:
|
||||
return func.call(that.context, work)
|
||||
case 2:
|
||||
return func.call(that.context, arguments[1], work)
|
||||
case 3:
|
||||
return func.call(that.context, arguments[1], arguments[2], work)
|
||||
case 4:
|
||||
return func.call(that.context, arguments[1], arguments[2], arguments[3], work)
|
||||
default:
|
||||
args = new Array(len)
|
||||
for (i = 1; i < len; i++) {
|
||||
args[i - 1] = arguments[i]
|
||||
}
|
||||
args[len - 1] = work
|
||||
func.apply(that.context, args)
|
||||
}
|
||||
} else {
|
||||
switch (len) {
|
||||
case 0:
|
||||
that.callback.call(that.context)
|
||||
break
|
||||
case 1:
|
||||
that.callback.call(that.context, arguments[0])
|
||||
break
|
||||
case 2:
|
||||
that.callback.call(that.context, arguments[0], arguments[1])
|
||||
break
|
||||
case 3:
|
||||
that.callback.call(that.context, arguments[0], arguments[1], arguments[2])
|
||||
break
|
||||
case 4:
|
||||
that.callback.call(that.context, arguments[0], arguments[1], arguments[2], arguments[3])
|
||||
break
|
||||
default:
|
||||
args = new Array(len)
|
||||
for (i = 0; i < len; i++) {
|
||||
args[i] = arguments[i]
|
||||
}
|
||||
that.callback.apply(that.context, args)
|
||||
}
|
||||
that.context = undefined
|
||||
that.list = empty
|
||||
that.count = 0
|
||||
that.release(that)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = fastfall
|
||||
54
backend/node_modules/fastfall/package.json
generated
vendored
Normal file
54
backend/node_modules/fastfall/package.json
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
{
|
||||
"name": "fastfall",
|
||||
"version": "1.5.1",
|
||||
"description": "call your callbacks in a waterfall, at speed",
|
||||
"main": "fall.js",
|
||||
"scripts": {
|
||||
"lint": "standard",
|
||||
"test": "tape test.js | faucet",
|
||||
"coverage": "istanbul cover tape test.js | tap-spec",
|
||||
"coveralls": "npm run coverage ; cat ./coverage/lcov.info | coveralls"
|
||||
},
|
||||
"precommit": [
|
||||
"lint",
|
||||
"test"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/mcollina/fastfall.git"
|
||||
},
|
||||
"keywords": [
|
||||
"async",
|
||||
"waterfall",
|
||||
"fall",
|
||||
"fast",
|
||||
"callback"
|
||||
],
|
||||
"author": "Matteo Collina <hello@matteocollina.com>",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/mcollina/fastfall/issues"
|
||||
},
|
||||
"homepage": "https://github.com/mcollina/fastfall#readme",
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"async": "^1.0.0",
|
||||
"coveralls": "^2.11.6",
|
||||
"fastbench": "^1.0.0",
|
||||
"faucet": "0.0.1",
|
||||
"insync": "^2.1.1",
|
||||
"istanbul": "^0.4.1",
|
||||
"neo-async": "^1.7.0",
|
||||
"pre-commit": "^1.0.10",
|
||||
"run-waterfall": "^1.1.1",
|
||||
"standard": "^5.0.0",
|
||||
"tap-spec": "^4.1.1",
|
||||
"tape": "^4.0.0",
|
||||
"waterfallize": "^1.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"reusify": "^1.0.0"
|
||||
}
|
||||
}
|
||||
193
backend/node_modules/fastfall/test.js
generated
vendored
Normal file
193
backend/node_modules/fastfall/test.js
generated
vendored
Normal file
@@ -0,0 +1,193 @@
|
||||
'use strict'
|
||||
|
||||
var test = require('tape')
|
||||
var fastfall = require('./')
|
||||
|
||||
test('basically works', function (t) {
|
||||
t.plan(22)
|
||||
|
||||
var fall = fastfall()
|
||||
|
||||
fall([
|
||||
function a (cb) {
|
||||
cb(null, 'a')
|
||||
},
|
||||
function b (a, cb) {
|
||||
t.equal(a, 'a', 'second function arg matches')
|
||||
cb(null, 'a', 'b')
|
||||
},
|
||||
function c (a, b, cb) {
|
||||
t.equal(a, 'a', 'third function 1st arg matches')
|
||||
t.equal(b, 'b', 'third function 2nd arg matches')
|
||||
cb(null, 'a', 'b', 'c')
|
||||
},
|
||||
function d (a, b, c, cb) {
|
||||
t.equal(a, 'a', 'fourth function 1st arg matches')
|
||||
t.equal(b, 'b', 'fourth function 2nd arg matches')
|
||||
t.equal(c, 'c', 'fourth function 3rd arg matches')
|
||||
cb(null, 'a', 'b', 'c', 'd')
|
||||
},
|
||||
function e (a, b, c, d, cb) {
|
||||
t.equal(a, 'a', 'fifth function 1st arg matches')
|
||||
t.equal(b, 'b', 'fifth function 2nd arg matches')
|
||||
t.equal(c, 'c', 'fifth function 3rd arg matches')
|
||||
t.equal(d, 'd', 'fifth function 4th arg matches')
|
||||
cb(null, 'a', 'b', 'c', 'd', 'e')
|
||||
},
|
||||
function f (a, b, c, d, e, cb) {
|
||||
t.equal(a, 'a', 'sixth function 1st arg matches')
|
||||
t.equal(b, 'b', 'sixth function 2nd arg matches')
|
||||
t.equal(c, 'c', 'sixth function 3rd arg matches')
|
||||
t.equal(d, 'd', 'sixth function 4th arg matches')
|
||||
t.equal(e, 'e', 'sixth function 5th arg matches')
|
||||
cb(null, 'a', 'b', 'c', 'd', 'e', 'f')
|
||||
}
|
||||
], function result (err, a, b, c, d, e, f) {
|
||||
t.error(err, 'no error')
|
||||
t.equal(a, 'a', 'result function 2nd arg matches')
|
||||
t.equal(b, 'b', 'result function 3rd arg matches')
|
||||
t.equal(c, 'c', 'result function 4th arg matches')
|
||||
t.equal(d, 'd', 'result function 5th arg matches')
|
||||
t.equal(e, 'e', 'result function 6th arg matches')
|
||||
t.equal(f, 'f', 'result function 7th arg matches')
|
||||
})
|
||||
})
|
||||
|
||||
test('call with error', function (t) {
|
||||
t.plan(4)
|
||||
|
||||
var fall = fastfall()
|
||||
|
||||
fall([
|
||||
function a (cb) {
|
||||
cb(null, 'a')
|
||||
},
|
||||
function b (a, cb) {
|
||||
t.equal(a, 'a', 'second function arg matches')
|
||||
cb(new Error('this is expected!'), 'a', 'b')
|
||||
},
|
||||
function c (a, b, cb) {
|
||||
t.fail('this should never happen')
|
||||
}
|
||||
], function result (err, a, b, c) {
|
||||
t.ok(err, 'error')
|
||||
t.notOk(a, 'no 2nd arg')
|
||||
t.notOk(b, 'no 3rd arg')
|
||||
})
|
||||
})
|
||||
|
||||
test('compiles a reusable fall', function (t) {
|
||||
t.plan(10)
|
||||
|
||||
var fall = fastfall([
|
||||
function a (arg, cb) {
|
||||
cb(null, arg)
|
||||
},
|
||||
function b (a, cb) {
|
||||
cb(null, a, 'b')
|
||||
},
|
||||
function c (a, b, cb) {
|
||||
t.equal(b, 'b', 'third function 2nd arg matches')
|
||||
cb(null, a, 'b', 'c')
|
||||
}
|
||||
])
|
||||
|
||||
fall(42, function result (err, a, b, c) {
|
||||
t.error(err, 'no error')
|
||||
t.equal(a, 42, 'result function 2nd arg matches')
|
||||
t.equal(b, 'b', 'result function 3rd arg matches')
|
||||
t.equal(c, 'c', 'result function 4th arg matches')
|
||||
})
|
||||
|
||||
fall(24, function result (err, a, b, c) {
|
||||
t.error(err, 'no error')
|
||||
t.equal(a, 24, 'result function 2nd arg matches')
|
||||
t.equal(b, 'b', 'result function 3rd arg matches')
|
||||
t.equal(c, 'c', 'result function 4th arg matches')
|
||||
})
|
||||
})
|
||||
|
||||
test('set this', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
var that = {}
|
||||
var fall = fastfall(that)
|
||||
|
||||
fall([
|
||||
function a (cb) {
|
||||
t.equal(this, that, 'this is set')
|
||||
cb(null, 'a')
|
||||
}
|
||||
], function result (err, a, b, c) {
|
||||
t.error(err, 'no error')
|
||||
})
|
||||
})
|
||||
|
||||
test('set this in compiled mode', function (t) {
|
||||
t.plan(4)
|
||||
|
||||
var that = {}
|
||||
var fall = fastfall(that, [
|
||||
function a (arg, cb) {
|
||||
t.equal(this, that, 'this is set')
|
||||
cb(null, arg)
|
||||
}
|
||||
])
|
||||
|
||||
fall(42, function result (err, a, b, c) {
|
||||
t.error(err, 'no error')
|
||||
t.equal(a, 42, 'result function 2nd arg matches')
|
||||
t.equal(this, that, 'this is set')
|
||||
})
|
||||
})
|
||||
|
||||
test('set this for a normal fall', function (t) {
|
||||
t.plan(4)
|
||||
|
||||
var that = {}
|
||||
var fall = fastfall()
|
||||
|
||||
fall(that, [
|
||||
function a (cb) {
|
||||
t.equal(this, that, 'this is set')
|
||||
cb(null, 'a')
|
||||
}
|
||||
], function result (err, a) {
|
||||
t.error(err, 'no error')
|
||||
t.equal(this, that, 'this is set')
|
||||
t.equal(a, 'a', 'result function 2nd arg matches')
|
||||
})
|
||||
})
|
||||
|
||||
test('use the this of the called object in compiled mode', function (t) {
|
||||
t.plan(4)
|
||||
|
||||
var that = {}
|
||||
var fall = fastfall([
|
||||
function a (arg, cb) {
|
||||
t.equal(this, that, 'this is set')
|
||||
cb(null, arg)
|
||||
}
|
||||
])
|
||||
|
||||
fall.call(that, 42, function result (err, a, b, c) {
|
||||
t.error(err, 'no error')
|
||||
t.equal(a, 42, 'result function 2nd arg matches')
|
||||
t.equal(this, that, 'this is set')
|
||||
})
|
||||
})
|
||||
|
||||
test('support errors in compiled mode', function (t) {
|
||||
t.plan(2)
|
||||
|
||||
var fall = fastfall([
|
||||
function a (arg, cb) {
|
||||
t.pass('function is called')
|
||||
cb(new Error('muahaha'), arg)
|
||||
}
|
||||
])
|
||||
|
||||
fall(42, function result (err) {
|
||||
t.ok(err, 'error is forwarded')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user