p-try
Advanced tools
Comparing version 1.0.0 to 2.0.0
'use strict'; | ||
module.exports = cb => new Promise(resolve => { | ||
resolve(cb()); | ||
module.exports = (callback, ...args) => new Promise(resolve => { | ||
resolve(callback(...args)); | ||
}); |
{ | ||
"name": "p-try", | ||
"version": "1.0.0", | ||
"description": "`Promise#try()` ponyfill - Starts a promise chain", | ||
"license": "MIT", | ||
"repository": "sindresorhus/p-try", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"promise", | ||
"try", | ||
"resolve", | ||
"function", | ||
"catch", | ||
"async", | ||
"await", | ||
"promises", | ||
"settled", | ||
"ponyfill", | ||
"polyfill", | ||
"shim", | ||
"bluebird" | ||
], | ||
"devDependencies": { | ||
"ava": "*", | ||
"xo": "*" | ||
}, | ||
"xo": { | ||
"esnext": true | ||
} | ||
"name": "p-try", | ||
"version": "2.0.0", | ||
"description": "`Start a promise chain", | ||
"license": "MIT", | ||
"repository": "sindresorhus/p-try", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=6" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"promise", | ||
"try", | ||
"resolve", | ||
"function", | ||
"catch", | ||
"async", | ||
"await", | ||
"promises", | ||
"settled", | ||
"ponyfill", | ||
"polyfill", | ||
"shim", | ||
"bluebird" | ||
], | ||
"devDependencies": { | ||
"ava": "*", | ||
"xo": "*" | ||
} | ||
} |
# p-try [![Build Status](https://travis-ci.org/sindresorhus/p-try.svg?branch=master)](https://travis-ci.org/sindresorhus/p-try) | ||
> [`Promise#try()`](https://github.com/ljharb/proposal-promise-try) [ponyfill](https://ponyfill.com) - Starts a promise chain | ||
> Start a promise chain | ||
@@ -11,3 +11,3 @@ [How is it useful?](http://cryto.net/~joepie91/blog/2016/05/11/what-is-promise-try-and-why-does-it-matter/) | ||
``` | ||
$ npm install --save p-try | ||
$ npm install p-try | ||
``` | ||
@@ -31,2 +31,11 @@ | ||
## API | ||
### pTry(fn, ...args) | ||
Returns a `Promise` resolved with the value of calling `fn(...args)`. If the function throws an error, the returned `Promise` will be rejected with that error. | ||
Support for passing arguments on to the `fn` is provided in order to be able to avoid creating unnecessary closures. You probably don't need this optimization unless you're pushing a *lot* of functions. | ||
## Related | ||
@@ -33,0 +42,0 @@ |
Sorry, the diff of this file is not supported yet
2987
48