first commit
This commit is contained in:
43
build/node_modules/wrap-fn/History.md
generated
vendored
Normal file
43
build/node_modules/wrap-fn/History.md
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
|
||||
0.1.5 / 2016-02-13
|
||||
==================
|
||||
|
||||
* fix note
|
||||
* deprecation note.
|
||||
|
||||
0.1.4 / 2015-01-21
|
||||
==================
|
||||
|
||||
* slim down the package
|
||||
* Use `files` property in package.json
|
||||
* Rename component dependency `visionmedia/co` to `tj/co`
|
||||
|
||||
0.1.3 / 2015-01-16
|
||||
==================
|
||||
|
||||
* fix return bug
|
||||
|
||||
0.1.2 / 2015-01-16
|
||||
==================
|
||||
|
||||
* catch uncaught synchronous errors in async functions
|
||||
|
||||
0.1.1 / 2014-09-24
|
||||
==================
|
||||
|
||||
* Add "scripts" field in `component.json`
|
||||
|
||||
0.1.0 / 2014-09-17
|
||||
==================
|
||||
|
||||
* Promises, synchronous errors and tests
|
||||
|
||||
0.0.2 / 2014-08-31
|
||||
==================
|
||||
|
||||
* use return value on sync functions
|
||||
|
||||
0.0.1 / 2010-01-03
|
||||
==================
|
||||
|
||||
* Initial release
|
||||
79
build/node_modules/wrap-fn/Readme.md
generated
vendored
Normal file
79
build/node_modules/wrap-fn/Readme.md
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
|
||||
**Deprecated in favor of: [wrapped](https://github.com/matthewmueller/wrapped).**
|
||||
|
||||
# wrap-fn
|
||||
|
||||
Low-level wrapper to support sync, async, promises, and generator functions.
|
||||
|
||||
## Installation
|
||||
|
||||
Node:
|
||||
|
||||
```bash
|
||||
$ npm install wrap-fn
|
||||
```
|
||||
|
||||
Duo:
|
||||
|
||||
```js
|
||||
var wrap = require('matthewmueller/wrap-fn');
|
||||
```
|
||||
|
||||
## Example
|
||||
|
||||
```js
|
||||
function *fn(a, b) {
|
||||
yield wait(100);
|
||||
// ...
|
||||
}
|
||||
|
||||
function next(err) {
|
||||
// Called after
|
||||
}
|
||||
|
||||
wrap(fn, next)('a', 'b')
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### `wrap(fn, [done])([args, ...])`
|
||||
|
||||
Wrap `fn` to support sync, async, promises and generator functions. Call `done` when finished.
|
||||
|
||||
`wrap` returns a function which you can pass arguments to or set the context.
|
||||
|
||||
```js
|
||||
wrap(fn).call(user, a, b, c, d);
|
||||
```
|
||||
|
||||
## Test
|
||||
|
||||
```js
|
||||
npm install
|
||||
make test
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2014 Matthew Mueller <mattmuelle@gmail.com>
|
||||
|
||||
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.
|
||||
125
build/node_modules/wrap-fn/index.js
generated
vendored
Normal file
125
build/node_modules/wrap-fn/index.js
generated
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
/**
|
||||
* Module Dependencies
|
||||
*/
|
||||
|
||||
var noop = function(){};
|
||||
var co = require('co');
|
||||
|
||||
/**
|
||||
* Export `wrap-fn`
|
||||
*/
|
||||
|
||||
module.exports = wrap;
|
||||
|
||||
/**
|
||||
* Wrap a function to support
|
||||
* sync, async, and gen functions.
|
||||
*
|
||||
* @param {Function} fn
|
||||
* @param {Function} done
|
||||
* @return {Function}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function wrap(fn, done) {
|
||||
done = once(done || noop);
|
||||
|
||||
return function() {
|
||||
// prevents arguments leakage
|
||||
// see https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#3-managing-arguments
|
||||
var i = arguments.length;
|
||||
var args = new Array(i);
|
||||
while (i--) args[i] = arguments[i];
|
||||
|
||||
var ctx = this;
|
||||
|
||||
// done
|
||||
if (!fn) {
|
||||
return done.apply(ctx, [null].concat(args));
|
||||
}
|
||||
|
||||
// async
|
||||
if (fn.length > args.length) {
|
||||
// NOTE: this only handles uncaught synchronous errors
|
||||
try {
|
||||
return fn.apply(ctx, args.concat(done));
|
||||
} catch (e) {
|
||||
return done(e);
|
||||
}
|
||||
}
|
||||
|
||||
// generator
|
||||
if (generator(fn)) {
|
||||
return co(fn).apply(ctx, args.concat(done));
|
||||
}
|
||||
|
||||
// sync
|
||||
return sync(fn, done).apply(ctx, args);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap a synchronous function execution.
|
||||
*
|
||||
* @param {Function} fn
|
||||
* @param {Function} done
|
||||
* @return {Function}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function sync(fn, done) {
|
||||
return function () {
|
||||
var ret;
|
||||
|
||||
try {
|
||||
ret = fn.apply(this, arguments);
|
||||
} catch (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
if (promise(ret)) {
|
||||
ret.then(function (value) { done(null, value); }, done);
|
||||
} else {
|
||||
ret instanceof Error ? done(ret) : done(null, ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is `value` a generator?
|
||||
*
|
||||
* @param {Mixed} value
|
||||
* @return {Boolean}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function generator(value) {
|
||||
return value
|
||||
&& value.constructor
|
||||
&& 'GeneratorFunction' == value.constructor.name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Is `value` a promise?
|
||||
*
|
||||
* @param {Mixed} value
|
||||
* @return {Boolean}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function promise(value) {
|
||||
return value && 'function' == typeof value.then;
|
||||
}
|
||||
|
||||
/**
|
||||
* Once
|
||||
*/
|
||||
|
||||
function once(fn) {
|
||||
return function() {
|
||||
var ret = fn.apply(this, arguments);
|
||||
fn = noop;
|
||||
return ret;
|
||||
};
|
||||
}
|
||||
371
build/node_modules/wrap-fn/node_modules/co/Readme.md
generated
vendored
Normal file
371
build/node_modules/wrap-fn/node_modules/co/Readme.md
generated
vendored
Normal file
@@ -0,0 +1,371 @@
|
||||
# Co
|
||||
|
||||
[](https://travis-ci.org/visionmedia/co)
|
||||
|
||||
Generator based flow-control goodness for nodejs and the browser, using
|
||||
thunks _or_ promises, letting you write non-blocking code in a nice-ish
|
||||
way.
|
||||
|
||||
Co is careful to relay any errors that occur back to the generator, including those
|
||||
within the thunk, or from the thunk's callback. "Uncaught" exceptions in the generator
|
||||
are passed to `co()`'s thunk.
|
||||
|
||||
Make sure to view the [examples](https://github.com/visionmedia/co/tree/master/examples).
|
||||
|
||||
## Platform Compatibility
|
||||
|
||||
When using node 0.11.x or greater, you must use the `--harmony-generators`
|
||||
flag or just `--harmony` to get access to generators.
|
||||
|
||||
When using node 0.10.x and lower or browsers without generator support,
|
||||
you must use [gnode](https://github.com/TooTallNate/gnode) and/or [regenerator](http://facebook.github.io/regenerator/).
|
||||
|
||||
When using node 0.8.x and lower or browsers without `setImmediate`,
|
||||
you must include a `setImmediate` polyfill.
|
||||
For a really simple polyfill, you may use [component/setimmediate.js](https://github.com/component/setimmediate.js).
|
||||
For a more robust polyfill, you may use [YuzuJS/setImmediate](https://github.com/YuzuJS/setImmediate).
|
||||
|
||||
## Installation
|
||||
|
||||
```
|
||||
$ npm install co
|
||||
```
|
||||
|
||||
## Associated libraries
|
||||
|
||||
View the [wiki](https://github.com/visionmedia/co/wiki) for libraries that
|
||||
work well with Co.
|
||||
|
||||
## Example
|
||||
|
||||
```js
|
||||
var co = require('co');
|
||||
var thunkify = require('thunkify');
|
||||
var request = require('request');
|
||||
var get = thunkify(request.get);
|
||||
|
||||
co(function *(){
|
||||
var a = yield get('http://google.com');
|
||||
var b = yield get('http://yahoo.com');
|
||||
var c = yield get('http://cloudup.com');
|
||||
console.log(a[0].statusCode);
|
||||
console.log(b[0].statusCode);
|
||||
console.log(c[0].statusCode);
|
||||
})()
|
||||
|
||||
co(function *(){
|
||||
var a = get('http://google.com');
|
||||
var b = get('http://yahoo.com');
|
||||
var c = get('http://cloudup.com');
|
||||
var res = yield [a, b, c];
|
||||
console.log(res);
|
||||
})()
|
||||
|
||||
// Error handling
|
||||
|
||||
co(function *(){
|
||||
try {
|
||||
var res = yield get('http://badhost.invalid');
|
||||
console.log(res);
|
||||
} catch(e) {
|
||||
console.log(e.code) // ENOTFOUND
|
||||
}
|
||||
})()
|
||||
```
|
||||
|
||||
## Yieldables
|
||||
|
||||
The "yieldable" objects currently supported are:
|
||||
|
||||
- promises
|
||||
- thunks (functions)
|
||||
- array (parallel execution)
|
||||
- objects (parallel execution)
|
||||
- generators (delegation)
|
||||
- generator functions (delegation)
|
||||
|
||||
To convert a regular node function that accepts a callback into one which returns a thunk you may want to use [thunkify](https://github.com/visionmedia/node-thunkify) or similar.
|
||||
|
||||
## Thunks vs promises
|
||||
|
||||
While co supports promises, you may return "thunks" from your functions,
|
||||
which otherwise behaves just like the traditional node-style callback
|
||||
with a signature of: `(err, result)`.
|
||||
|
||||
|
||||
For example take `fs.readFile`, we all know the signature is:
|
||||
|
||||
```js
|
||||
fs.readFile(path, encoding, function(err, result){
|
||||
|
||||
});
|
||||
```
|
||||
|
||||
To work with Co we need a function to return another function of
|
||||
the same signature:
|
||||
|
||||
```js
|
||||
fs.readFile(path, encoding)(function(err, result){
|
||||
|
||||
});
|
||||
```
|
||||
|
||||
Which basically looks like this:
|
||||
|
||||
```js
|
||||
function read(path, encoding) {
|
||||
return function(cb){
|
||||
fs.readFile(path, encoding, cb);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
or to execute immediately like this (see [`thunkify`](https://github.com/visionmedia/node-thunkify)):
|
||||
|
||||
```js
|
||||
function read(path, encoding) {
|
||||
// call fs.readFile immediately, store result later
|
||||
return function(cb){
|
||||
// cb(err, result) or when result ready
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Receiver propagation
|
||||
|
||||
When `co` is invoked with a receiver it will propagate to most yieldables,
|
||||
allowing you to alter `this`.
|
||||
|
||||
```js
|
||||
var ctx = {};
|
||||
|
||||
function foo() {
|
||||
assert(this == ctx);
|
||||
}
|
||||
|
||||
co(function *(){
|
||||
assert(this == ctx);
|
||||
yield foo;
|
||||
}).call(ctx)
|
||||
```
|
||||
|
||||
You also pass arguments through the generator:
|
||||
|
||||
```js
|
||||
co(function *(a){
|
||||
assert(this == ctx);
|
||||
assert('yay' == a);
|
||||
yield foo;
|
||||
}).call(ctx, 'yay');
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### co(fn)
|
||||
|
||||
Pass a generator `fn` and return a thunk. The thunk's signature is
|
||||
`(err, result)`, where `result` is the value passed to the `return`
|
||||
statement.
|
||||
|
||||
```js
|
||||
var co = require('co');
|
||||
var fs = require('fs');
|
||||
|
||||
function read(file) {
|
||||
return function(fn){
|
||||
fs.readFile(file, 'utf8', fn);
|
||||
}
|
||||
}
|
||||
|
||||
co(function *(){
|
||||
var a = yield read('.gitignore');
|
||||
var b = yield read('Makefile');
|
||||
var c = yield read('package.json');
|
||||
return [a, b, c];
|
||||
})()
|
||||
```
|
||||
|
||||
You may also yield `Generator` objects to support nesting:
|
||||
|
||||
|
||||
```js
|
||||
var co = require('co');
|
||||
var fs = require('fs');
|
||||
|
||||
function size(file) {
|
||||
return function(fn){
|
||||
fs.stat(file, function(err, stat){
|
||||
if (err) return fn(err);
|
||||
fn(null, stat.size);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function *foo(){
|
||||
var a = yield size('.gitignore');
|
||||
var b = yield size('Makefile');
|
||||
var c = yield size('package.json');
|
||||
return [a, b, c];
|
||||
}
|
||||
|
||||
function *bar(){
|
||||
var a = yield size('examples/parallel.js');
|
||||
var b = yield size('examples/nested.js');
|
||||
var c = yield size('examples/simple.js');
|
||||
return [a, b, c];
|
||||
}
|
||||
|
||||
co(function *(){
|
||||
var results = yield [foo(), bar()];
|
||||
console.log(results);
|
||||
})()
|
||||
```
|
||||
|
||||
Or if the generator functions do not require arguments, simply `yield` the function:
|
||||
|
||||
```js
|
||||
var co = require('co');
|
||||
var thunkify = require('thunkify');
|
||||
var request = require('request');
|
||||
|
||||
var get = thunkify(request.get);
|
||||
|
||||
function *results() {
|
||||
var a = get('http://google.com')
|
||||
var b = get('http://yahoo.com')
|
||||
var c = get('http://ign.com')
|
||||
return yield [a, b, c]
|
||||
}
|
||||
|
||||
co(function *(){
|
||||
// 3 concurrent requests at a time
|
||||
var a = yield results;
|
||||
var b = yield results;
|
||||
console.log(a, b);
|
||||
|
||||
// 6 concurrent requests
|
||||
console.log(yield [results, results]);
|
||||
})()
|
||||
```
|
||||
|
||||
If a thunk is written to execute immediately you may achieve parallelism
|
||||
by simply `yield`-ing _after_ the call. The following are equivalent if
|
||||
each call kicks off execution immediately:
|
||||
|
||||
```js
|
||||
co(function *(){
|
||||
var a = size('package.json');
|
||||
var b = size('Readme.md');
|
||||
var c = size('Makefile');
|
||||
|
||||
return [yield a, yield b, yield c];
|
||||
})()
|
||||
```
|
||||
|
||||
Or:
|
||||
|
||||
```js
|
||||
co(function *(){
|
||||
var a = size('package.json');
|
||||
var b = size('Readme.md');
|
||||
var c = size('Makefile');
|
||||
|
||||
return yield [a, b, c];
|
||||
})()
|
||||
```
|
||||
|
||||
You can also pass arguments into the generator. The last argument, `done`, is
|
||||
the callback function. Here's an example:
|
||||
|
||||
```js
|
||||
var exec = require('co-exec');
|
||||
co(function *(cmd) {
|
||||
var res = yield exec(cmd);
|
||||
return res;
|
||||
})('pwd', done);
|
||||
```
|
||||
|
||||
### yield array
|
||||
|
||||
By yielding an array of thunks you may "join" them all into a single thunk which executes them all concurrently,
|
||||
instead of in sequence. Note that the resulting array ordering _is_ retained.
|
||||
|
||||
```js
|
||||
|
||||
var co = require('co');
|
||||
var fs = require('fs');
|
||||
|
||||
function size(file) {
|
||||
return function(fn){
|
||||
fs.stat(file, function(err, stat){
|
||||
if (err) return fn(err);
|
||||
fn(null, stat.size);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
co(function *(){
|
||||
var a = size('.gitignore');
|
||||
var b = size('index.js');
|
||||
var c = size('Makefile');
|
||||
var res = yield [a, b, c];
|
||||
console.log(res);
|
||||
// => [ 13, 1687, 129 ]
|
||||
})()
|
||||
```
|
||||
|
||||
Nested arrays may also be expressed as simple nested arrays:
|
||||
|
||||
```js
|
||||
var a = [
|
||||
get('http://google.com'),
|
||||
get('http://yahoo.com'),
|
||||
get('http://ign.com')
|
||||
];
|
||||
|
||||
var b = [
|
||||
get('http://google.com'),
|
||||
get('http://yahoo.com'),
|
||||
get('http://ign.com')
|
||||
];
|
||||
|
||||
console.log(yield [a, b]);
|
||||
```
|
||||
|
||||
### yield object
|
||||
|
||||
Yielding an object behaves much like yielding an array, however recursion is supported:
|
||||
|
||||
```js
|
||||
co(function *(){
|
||||
var user = yield {
|
||||
name: {
|
||||
first: get('name.first'),
|
||||
last: get('name.last')
|
||||
}
|
||||
};
|
||||
})()
|
||||
```
|
||||
|
||||
Here is the sequential equivalent without yielding an object:
|
||||
|
||||
```js
|
||||
co(function *(){
|
||||
var user = {
|
||||
name: {
|
||||
first: yield get('name.first'),
|
||||
last: yield get('name.last')
|
||||
}
|
||||
};
|
||||
})()
|
||||
```
|
||||
|
||||
### Performance
|
||||
|
||||
On my machine 30,000 sequential stat()s takes an avg of 570ms,
|
||||
while the same number of sequential stat()s with `co()` takes
|
||||
610ms, aka the overhead introduced by generators is _extremely_ negligible.
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
294
build/node_modules/wrap-fn/node_modules/co/index.js
generated
vendored
Normal file
294
build/node_modules/wrap-fn/node_modules/co/index.js
generated
vendored
Normal file
@@ -0,0 +1,294 @@
|
||||
|
||||
/**
|
||||
* slice() reference.
|
||||
*/
|
||||
|
||||
var slice = Array.prototype.slice;
|
||||
|
||||
/**
|
||||
* Expose `co`.
|
||||
*/
|
||||
|
||||
module.exports = co;
|
||||
|
||||
/**
|
||||
* Wrap the given generator `fn` and
|
||||
* return a thunk.
|
||||
*
|
||||
* @param {Function} fn
|
||||
* @return {Function}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function co(fn) {
|
||||
var isGenFun = isGeneratorFunction(fn);
|
||||
|
||||
return function (done) {
|
||||
var ctx = this;
|
||||
|
||||
// in toThunk() below we invoke co()
|
||||
// with a generator, so optimize for
|
||||
// this case
|
||||
var gen = fn;
|
||||
|
||||
// we only need to parse the arguments
|
||||
// if gen is a generator function.
|
||||
if (isGenFun) {
|
||||
var args = slice.call(arguments), len = args.length;
|
||||
var hasCallback = len && 'function' == typeof args[len - 1];
|
||||
done = hasCallback ? args.pop() : error;
|
||||
gen = fn.apply(this, args);
|
||||
} else {
|
||||
done = done || error;
|
||||
}
|
||||
|
||||
next();
|
||||
|
||||
// #92
|
||||
// wrap the callback in a setImmediate
|
||||
// so that any of its errors aren't caught by `co`
|
||||
function exit(err, res) {
|
||||
setImmediate(function(){
|
||||
done.call(ctx, err, res);
|
||||
});
|
||||
}
|
||||
|
||||
function next(err, res) {
|
||||
var ret;
|
||||
|
||||
// multiple args
|
||||
if (arguments.length > 2) res = slice.call(arguments, 1);
|
||||
|
||||
// error
|
||||
if (err) {
|
||||
try {
|
||||
ret = gen.throw(err);
|
||||
} catch (e) {
|
||||
return exit(e);
|
||||
}
|
||||
}
|
||||
|
||||
// ok
|
||||
if (!err) {
|
||||
try {
|
||||
ret = gen.next(res);
|
||||
} catch (e) {
|
||||
return exit(e);
|
||||
}
|
||||
}
|
||||
|
||||
// done
|
||||
if (ret.done) return exit(null, ret.value);
|
||||
|
||||
// normalize
|
||||
ret.value = toThunk(ret.value, ctx);
|
||||
|
||||
// run
|
||||
if ('function' == typeof ret.value) {
|
||||
var called = false;
|
||||
try {
|
||||
ret.value.call(ctx, function(){
|
||||
if (called) return;
|
||||
called = true;
|
||||
next.apply(ctx, arguments);
|
||||
});
|
||||
} catch (e) {
|
||||
setImmediate(function(){
|
||||
if (called) return;
|
||||
called = true;
|
||||
next(e);
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// invalid
|
||||
next(new TypeError('You may only yield a function, promise, generator, array, or object, '
|
||||
+ 'but the following was passed: "' + String(ret.value) + '"'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert `obj` into a normalized thunk.
|
||||
*
|
||||
* @param {Mixed} obj
|
||||
* @param {Mixed} ctx
|
||||
* @return {Function}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function toThunk(obj, ctx) {
|
||||
|
||||
if (isGeneratorFunction(obj)) {
|
||||
return co(obj.call(ctx));
|
||||
}
|
||||
|
||||
if (isGenerator(obj)) {
|
||||
return co(obj);
|
||||
}
|
||||
|
||||
if (isPromise(obj)) {
|
||||
return promiseToThunk(obj);
|
||||
}
|
||||
|
||||
if ('function' == typeof obj) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
if (isObject(obj) || Array.isArray(obj)) {
|
||||
return objectToThunk.call(ctx, obj);
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an object of yieldables to a thunk.
|
||||
*
|
||||
* @param {Object} obj
|
||||
* @return {Function}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function objectToThunk(obj){
|
||||
var ctx = this;
|
||||
var isArray = Array.isArray(obj);
|
||||
|
||||
return function(done){
|
||||
var keys = Object.keys(obj);
|
||||
var pending = keys.length;
|
||||
var results = isArray
|
||||
? new Array(pending) // predefine the array length
|
||||
: new obj.constructor();
|
||||
var finished;
|
||||
|
||||
if (!pending) {
|
||||
setImmediate(function(){
|
||||
done(null, results)
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// prepopulate object keys to preserve key ordering
|
||||
if (!isArray) {
|
||||
for (var i = 0; i < pending; i++) {
|
||||
results[keys[i]] = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
run(obj[keys[i]], keys[i]);
|
||||
}
|
||||
|
||||
function run(fn, key) {
|
||||
if (finished) return;
|
||||
try {
|
||||
fn = toThunk(fn, ctx);
|
||||
|
||||
if ('function' != typeof fn) {
|
||||
results[key] = fn;
|
||||
return --pending || done(null, results);
|
||||
}
|
||||
|
||||
fn.call(ctx, function(err, res){
|
||||
if (finished) return;
|
||||
|
||||
if (err) {
|
||||
finished = true;
|
||||
return done(err);
|
||||
}
|
||||
|
||||
results[key] = res;
|
||||
--pending || done(null, results);
|
||||
});
|
||||
} catch (err) {
|
||||
finished = true;
|
||||
done(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert `promise` to a thunk.
|
||||
*
|
||||
* @param {Object} promise
|
||||
* @return {Function}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function promiseToThunk(promise) {
|
||||
return function(fn){
|
||||
promise.then(function(res) {
|
||||
fn(null, res);
|
||||
}, fn);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if `obj` is a promise.
|
||||
*
|
||||
* @param {Object} obj
|
||||
* @return {Boolean}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function isPromise(obj) {
|
||||
return obj && 'function' == typeof obj.then;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if `obj` is a generator.
|
||||
*
|
||||
* @param {Mixed} obj
|
||||
* @return {Boolean}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function isGenerator(obj) {
|
||||
return obj && 'function' == typeof obj.next && 'function' == typeof obj.throw;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if `obj` is a generator function.
|
||||
*
|
||||
* @param {Mixed} obj
|
||||
* @return {Boolean}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function isGeneratorFunction(obj) {
|
||||
return obj && obj.constructor && 'GeneratorFunction' == obj.constructor.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for plain object.
|
||||
*
|
||||
* @param {Mixed} val
|
||||
* @return {Boolean}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function isObject(val) {
|
||||
return val && Object == val.constructor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw `err` in a new stack.
|
||||
*
|
||||
* This is used when co() is invoked
|
||||
* without supplying a callback, which
|
||||
* should only be for demonstrational
|
||||
* purposes.
|
||||
*
|
||||
* @param {Error} err
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function error(err) {
|
||||
if (!err) return;
|
||||
setImmediate(function(){
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
63
build/node_modules/wrap-fn/node_modules/co/package.json
generated
vendored
Normal file
63
build/node_modules/wrap-fn/node_modules/co/package.json
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"co@3.1.0",
|
||||
"/Users/asciidisco/Desktop/asciidisco.com/build"
|
||||
]
|
||||
],
|
||||
"_from": "co@3.1.0",
|
||||
"_id": "co@3.1.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-TqVOpaCJOBUxheFSEMaNkJK8G3g=",
|
||||
"_location": "/wrap-fn/co",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "co@3.1.0",
|
||||
"name": "co",
|
||||
"escapedName": "co",
|
||||
"rawSpec": "3.1.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "3.1.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/wrap-fn"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/co/-/co-3.1.0.tgz",
|
||||
"_spec": "3.1.0",
|
||||
"_where": "/Users/asciidisco/Desktop/asciidisco.com/build",
|
||||
"bugs": {
|
||||
"url": "https://github.com/visionmedia/co/issues"
|
||||
},
|
||||
"description": "generator async flow control goodness",
|
||||
"devDependencies": {
|
||||
"bluebird": "^2.0.0",
|
||||
"matcha": "~0.5.0",
|
||||
"mocha": "^1.12.0",
|
||||
"request": "^2.36.0",
|
||||
"should": "^3.0.0",
|
||||
"thunkify": "^2.0.0"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"homepage": "https://github.com/visionmedia/co#readme",
|
||||
"keywords": [
|
||||
"async",
|
||||
"flow",
|
||||
"generator",
|
||||
"coro",
|
||||
"coroutine"
|
||||
],
|
||||
"license": "MIT",
|
||||
"name": "co",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/visionmedia/co.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "make test"
|
||||
},
|
||||
"version": "3.1.0"
|
||||
}
|
||||
68
build/node_modules/wrap-fn/package.json
generated
vendored
Normal file
68
build/node_modules/wrap-fn/package.json
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"wrap-fn@0.1.5",
|
||||
"/Users/asciidisco/Desktop/asciidisco.com/build"
|
||||
]
|
||||
],
|
||||
"_from": "wrap-fn@0.1.5",
|
||||
"_id": "wrap-fn@0.1.5",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-8htuQQFv9KfjFyDbxjoJAWvfmEU=",
|
||||
"_location": "/wrap-fn",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "wrap-fn@0.1.5",
|
||||
"name": "wrap-fn",
|
||||
"escapedName": "wrap-fn",
|
||||
"rawSpec": "0.1.5",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "0.1.5"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/ware"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/wrap-fn/-/wrap-fn-0.1.5.tgz",
|
||||
"_spec": "0.1.5",
|
||||
"_where": "/Users/asciidisco/Desktop/asciidisco.com/build",
|
||||
"author": {
|
||||
"name": "Matthew Mueller",
|
||||
"email": "mattmuelle@gmail.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/MatthewMueller/wrap-fn/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"co": "3.1.0"
|
||||
},
|
||||
"description": "support sync, async, and generator functions",
|
||||
"devDependencies": {
|
||||
"duo": "^0.8.2",
|
||||
"duo-test": "^0.3.2",
|
||||
"generator-support": "0.0.1",
|
||||
"gnode": "0.0.8",
|
||||
"mocha": "*",
|
||||
"should": "*"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"homepage": "https://github.com/MatthewMueller/wrap-fn#readme",
|
||||
"keywords": [
|
||||
"browser",
|
||||
"wrap",
|
||||
"generator"
|
||||
],
|
||||
"license": "MIT",
|
||||
"name": "wrap-fn",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/MatthewMueller/wrap-fn.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "make test"
|
||||
},
|
||||
"version": "0.1.5"
|
||||
}
|
||||
Reference in New Issue
Block a user