diff options
Diffstat (limited to 'tools/node_modules/eslint/node_modules/run-async')
4 files changed, 225 insertions, 0 deletions
diff --git a/tools/node_modules/eslint/node_modules/run-async/LICENSE b/tools/node_modules/eslint/node_modules/run-async/LICENSE new file mode 100644 index 0000000000..e895e99b5e --- /dev/null +++ b/tools/node_modules/eslint/node_modules/run-async/LICENSE @@ -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. diff --git a/tools/node_modules/eslint/node_modules/run-async/README.md b/tools/node_modules/eslint/node_modules/run-async/README.md new file mode 100644 index 0000000000..8eb62c2406 --- /dev/null +++ b/tools/node_modules/eslint/node_modules/run-async/README.md @@ -0,0 +1,79 @@ +Run Async +========= + +[![npm](https://badge.fury.io/js/run-async.svg)](http://badge.fury.io/js/run-async) [![tests](https://travis-ci.org/SBoudrias/run-async.svg?branch=master)](http://travis-ci.org/SBoudrias/run-async) [![dependencies](https://david-dm.org/SBoudrias/run-async.svg?theme=shields.io)](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'; +}); +``` + +### 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. diff --git a/tools/node_modules/eslint/node_modules/run-async/index.js b/tools/node_modules/eslint/node_modules/run-async/index.js new file mode 100644 index 0000000000..f623326c7e --- /dev/null +++ b/tools/node_modules/eslint/node_modules/run-async/index.js @@ -0,0 +1,61 @@ +'use strict'; + +var isPromise = require('is-promise'); + +/** + * 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 + * @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) { + cb = cb || function () {}; + + return function () { + var async = false; + var args = arguments; + + var promise = new Promise(function (resolve, reject) { + var answer = func.apply({ + async: function () { + async = true; + return function (err, value) { + if (err) { + reject(err); + } else { + resolve(value); + } + }; + } + }, Array.prototype.slice.call(args)); + + if (!async) { + if (isPromise(answer)) { + answer.then(resolve, reject); + } else { + resolve(answer); + } + } + }); + + 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); +}; diff --git a/tools/node_modules/eslint/node_modules/run-async/package.json b/tools/node_modules/eslint/node_modules/run-async/package.json new file mode 100644 index 0000000000..5396174ddb --- /dev/null +++ b/tools/node_modules/eslint/node_modules/run-async/package.json @@ -0,0 +1,64 @@ +{ + "_from": "run-async@^2.2.0", + "_id": "run-async@2.3.0", + "_inBundle": false, + "_integrity": "sha1-A3GrSuC91yDUFm19/aZP96RFpsA=", + "_location": "/eslint/run-async", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "run-async@^2.2.0", + "name": "run-async", + "escapedName": "run-async", + "rawSpec": "^2.2.0", + "saveSpec": null, + "fetchSpec": "^2.2.0" + }, + "_requiredBy": [ + "/eslint/inquirer" + ], + "_resolved": "https://registry.npmjs.org/run-async/-/run-async-2.3.0.tgz", + "_shasum": "0371ab4ae0bdd720d4166d7dfda64ff7a445a6c0", + "_spec": "run-async@^2.2.0", + "_where": "/Users/cjihrig/iojs/node/tools/eslint-tmp/node_modules/eslint/node_modules/inquirer", + "author": { + "name": "Simon Boudrias", + "email": "admin@simonboudrias.com" + }, + "bugs": { + "url": "https://github.com/SBoudrias/run-async/issues" + }, + "bundleDependencies": false, + "dependencies": { + "is-promise": "^2.1.0" + }, + "deprecated": false, + "description": "Utility method to run function either synchronously or asynchronously using the common `this.async()` style.", + "devDependencies": { + "mocha": "^3.1.2" + }, + "engines": { + "node": ">=0.12.0" + }, + "files": [ + "index.js" + ], + "homepage": "https://github.com/SBoudrias/run-async#readme", + "keywords": [ + "flow", + "flow-control", + "async" + ], + "license": "MIT", + "main": "index.js", + "name": "run-async", + "repository": { + "type": "git", + "url": "git+https://github.com/SBoudrias/run-async.git" + }, + "scripts": { + "test": "mocha -R spec" + }, + "version": "2.3.0" +} |