Updated the files.
This commit is contained in:
parent
1553e6b971
commit
753967d4f5
23418 changed files with 3784666 additions and 0 deletions
21
my-app/node_modules/run-async/LICENSE
generated
vendored
Executable file
21
my-app/node_modules/run-async/LICENSE
generated
vendored
Executable file
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Simon Boudrias
|
||||
|
||||
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.
|
100
my-app/node_modules/run-async/README.md
generated
vendored
Executable file
100
my-app/node_modules/run-async/README.md
generated
vendored
Executable file
|
@ -0,0 +1,100 @@
|
|||
Run Async
|
||||
=========
|
||||
|
||||
[](http://badge.fury.io/js/run-async) [](http://travis-ci.org/SBoudrias/run-async) [](https://david-dm.org/SBoudrias/run-async)
|
||||
|
||||
Utility method to run a function either synchronously or asynchronously using a series of common patterns. This is useful for library author accepting sync or async functions as parameter. `runAsync` will always run them as an async method, and normalize the multiple signature.
|
||||
|
||||
Installation
|
||||
=========
|
||||
|
||||
```bash
|
||||
npm install --save run-async
|
||||
```
|
||||
|
||||
Usage
|
||||
=========
|
||||
|
||||
Here's a simple example print the function results and three options a user can provide a function.
|
||||
|
||||
```js
|
||||
var runAsync = require('run-async');
|
||||
|
||||
var printAfter = function (func) {
|
||||
var cb = function (err, returnValue) {
|
||||
console.log(returnValue);
|
||||
};
|
||||
runAsync(func, cb)(/* arguments for func */);
|
||||
};
|
||||
```
|
||||
|
||||
#### Using `this.async`
|
||||
```js
|
||||
printAfter(function () {
|
||||
var done = this.async();
|
||||
|
||||
setTimeout(function () {
|
||||
done(null, 'done running with callback');
|
||||
}, 10);
|
||||
});
|
||||
```
|
||||
|
||||
#### Returning a promise
|
||||
```js
|
||||
printAfter(function () {
|
||||
return new Promise(function (resolve, reject) {
|
||||
resolve('done running with promises');
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
#### Synchronous function
|
||||
```js
|
||||
printAfter(function () {
|
||||
return 'done running sync function';
|
||||
});
|
||||
```
|
||||
|
||||
#### Custom done factory
|
||||
```js
|
||||
var runAsync = require('run-async');
|
||||
|
||||
runAsync(function() {
|
||||
var callback = this.customAsync();
|
||||
callback(null, a + b);
|
||||
}, 'customAsync')(1, 2)
|
||||
```
|
||||
|
||||
#### Passing context to async method
|
||||
```js
|
||||
var runAsync = require('run-async');
|
||||
|
||||
runAsync(function() {
|
||||
assert(this.isBound);
|
||||
var callback = this.async();
|
||||
callback(null, a + b);
|
||||
}).call({ isBound: true }, 1, 2)
|
||||
```
|
||||
|
||||
### runAsync.cb
|
||||
|
||||
`runAsync.cb` supports all the function types that `runAsync` does and additionally a traditional **callback as the last argument** signature:
|
||||
|
||||
```js
|
||||
var runAsync = require('run-async');
|
||||
|
||||
// IMPORTANT: The wrapped function must have a fixed number of parameters.
|
||||
runAsync.cb(function(a, b, cb) {
|
||||
cb(null, a + b);
|
||||
}, function(err, result) {
|
||||
console.log(result)
|
||||
})(1, 2)
|
||||
```
|
||||
|
||||
If your version of node support Promises natively (node >= 0.12), `runAsync` will return a promise. Example: `runAsync(func)(arg1, arg2).then(cb)`
|
||||
|
||||
Licence
|
||||
========
|
||||
|
||||
Copyright (c) 2014 Simon Boudrias (twitter: @vaxilart)
|
||||
Licensed under the MIT license.
|
122
my-app/node_modules/run-async/index.js
generated
vendored
Executable file
122
my-app/node_modules/run-async/index.js
generated
vendored
Executable file
|
@ -0,0 +1,122 @@
|
|||
'use strict';
|
||||
|
||||
function isPromise(obj) {
|
||||
return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a function that will run a function asynchronously or synchronously
|
||||
*
|
||||
* example:
|
||||
* runAsync(wrappedFunction, callback)(...args);
|
||||
*
|
||||
* @param {Function} func Function to run
|
||||
* @param {Function} [cb] Callback function passed the `func` returned value
|
||||
* @param {string} [proxyProperty] `this` property to be used for the callback factory
|
||||
* @return {Function(arguments)} Arguments to pass to `func`. This function will in turn
|
||||
* return a Promise (Node >= 0.12) or call the callbacks.
|
||||
*/
|
||||
|
||||
var runAsync = module.exports = function (func, cb, proxyProperty = 'async') {
|
||||
if (typeof cb === 'string') {
|
||||
proxyProperty = cb;
|
||||
cb = undefined;
|
||||
}
|
||||
cb = cb || function () {};
|
||||
|
||||
return function () {
|
||||
|
||||
var args = arguments;
|
||||
var originalThis = this;
|
||||
|
||||
var promise = new Promise(function (resolve, reject) {
|
||||
var resolved = false;
|
||||
const wrappedResolve = function (value) {
|
||||
if (resolved) {
|
||||
console.warn('Run-async promise already resolved.')
|
||||
}
|
||||
resolved = true;
|
||||
resolve(value);
|
||||
}
|
||||
|
||||
var rejected = false;
|
||||
const wrappedReject = function (value) {
|
||||
if (rejected) {
|
||||
console.warn('Run-async promise already rejected.')
|
||||
}
|
||||
rejected = true;
|
||||
reject(value);
|
||||
}
|
||||
|
||||
var usingCallback = false;
|
||||
var callbackConflict = false;
|
||||
var contextEnded = false;
|
||||
|
||||
var doneFactory = function () {
|
||||
if (contextEnded) {
|
||||
console.warn('Run-async async() called outside a valid run-async context, callback will be ignored.');
|
||||
return function() {};
|
||||
}
|
||||
if (callbackConflict) {
|
||||
console.warn('Run-async wrapped function (async) returned a promise.\nCalls to async() callback can have unexpected results.');
|
||||
}
|
||||
usingCallback = true;
|
||||
return function (err, value) {
|
||||
if (err) {
|
||||
wrappedReject(err);
|
||||
} else {
|
||||
wrappedResolve(value);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var _this;
|
||||
if (originalThis && proxyProperty && Proxy) {
|
||||
_this = new Proxy(originalThis, {
|
||||
get(_target, prop) {
|
||||
if (prop === proxyProperty) {
|
||||
if (prop in _target) {
|
||||
console.warn(`${proxyProperty} property is been shadowed by run-sync`);
|
||||
}
|
||||
return doneFactory;
|
||||
}
|
||||
|
||||
return Reflect.get(...arguments);
|
||||
},
|
||||
});
|
||||
} else {
|
||||
_this = { [proxyProperty]: doneFactory };
|
||||
}
|
||||
|
||||
var answer = func.apply(_this, Array.prototype.slice.call(args));
|
||||
|
||||
if (usingCallback) {
|
||||
if (isPromise(answer)) {
|
||||
console.warn('Run-async wrapped function (sync) returned a promise but async() callback must be executed to resolve.');
|
||||
}
|
||||
} else {
|
||||
if (isPromise(answer)) {
|
||||
callbackConflict = true;
|
||||
answer.then(wrappedResolve, wrappedReject);
|
||||
} else {
|
||||
wrappedResolve(answer);
|
||||
}
|
||||
}
|
||||
contextEnded = true;
|
||||
});
|
||||
|
||||
promise.then(cb.bind(null, null), cb);
|
||||
|
||||
return promise;
|
||||
}
|
||||
};
|
||||
|
||||
runAsync.cb = function (func, cb) {
|
||||
return runAsync(function () {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
if (args.length === func.length - 1) {
|
||||
args.push(this.async());
|
||||
}
|
||||
return func.apply(this, args);
|
||||
}, cb);
|
||||
};
|
26
my-app/node_modules/run-async/package.json
generated
vendored
Executable file
26
my-app/node_modules/run-async/package.json
generated
vendored
Executable file
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"name": "run-async",
|
||||
"version": "3.0.0",
|
||||
"description": "Utility method to run function either synchronously or asynchronously using the common `this.async()` style.",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "mocha -R spec"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.12.0"
|
||||
},
|
||||
"repository": "SBoudrias/run-async",
|
||||
"keywords": [
|
||||
"flow",
|
||||
"flow-control",
|
||||
"async"
|
||||
],
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"author": "Simon Boudrias <admin@simonboudrias.com>",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"mocha": "^10.2.0"
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue