Compare commits

...

4 Commits

Author SHA1 Message Date
Sven Slootweg b1b7125638 1.0.0 8 years ago
Sven Slootweg e07c830568 Add a changelog 8 years ago
Sven Slootweg f7eaf15e46 Add documentation 8 years ago
Sven Slootweg 4d42cb07a0 Add missing semicolon 8 years ago

@ -0,0 +1,10 @@
## 1.0.0 (August 16, 2016)
First stable and documented release - however, the functionality or API has not changed from `0.0.1`.
* __Patch:__ Added a missing semicolon.
* __Documentation:__ Added documentation and a changelog.
## 0.0.1 (April 17, 2016)
Initial release.

@ -1,6 +1,10 @@
# es6-promise-try # es6-promise-try
A Promise.try shim for ES6 Promises. A `Promise.try` shim for ES6 Promises.
`Promise.try` is an important tool for writing robust and readable code with Promises ([this article](http://cryto.net/~joepie91/blog/2016/05/11/what-is-promise-try-and-why-does-it-matter/) explains why), but ES6 Promises do not ([yet](https://github.com/ljharb/proposal-promise-try)) include this in their specification. This module provides an implementation of `Promise.try` for ES6 Promises that can be used stand-alone, without modifying `Promise`'s prototype.
The goal of this module is to be *functionally equivalent* to Bluebird's `Promise.try` implementation. If you find that it behaves differently in some way, please file a bug.
## License ## License
@ -22,8 +26,22 @@ Be aware that by making a pull request, you agree to release your modifications
## Usage ## Usage
TODO An example from [the article](http://cryto.net/~joepie91/blog/2016/05/11/what-is-promise-try-and-why-does-it-matter/):
```javascript
var promiseTry = require("es6-promise-try");
function getUsername(userId) {
return promiseTry(function() {
return database.users.get({id: userID});
}).then(function(user) {
return user.name;
});
}
```
## API ## API
TODO ### promiseTry(func)
Immediately invokes `func` - in the same tick of the event loop - and wraps it to provide error-handling and Promises/A+ compatibility, as described in [the article](http://cryto.net/~joepie91/blog/2016/05/11/what-is-promise-try-and-why-does-it-matter/). Functionally equivalent to [Bluebird's `Promise.try`](http://bluebirdjs.com/docs/api/promise.try.html).

@ -1,6 +1,6 @@
{ {
"name": "es6-promise-try", "name": "es6-promise-try",
"version": "0.0.1", "version": "1.0.0",
"description": "Promise.try shim for ES6 Promises", "description": "Promise.try shim for ES6 Promises",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
@ -17,8 +17,7 @@
], ],
"author": "Sven Slootweg", "author": "Sven Slootweg",
"license": "WTFPL", "license": "WTFPL",
"dependencies": { "dependencies": {},
},
"devDependencies": { "devDependencies": {
"@joepie91/gulp-preset-es2015": "^1.0.1", "@joepie91/gulp-preset-es2015": "^1.0.1",
"babel-preset-es2015": "^6.6.0", "babel-preset-es2015": "^6.6.0",

@ -3,5 +3,5 @@
module.exports = function promiseTry(func) { module.exports = function promiseTry(func) {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
resolve(func()); resolve(func());
}) });
} }
Loading…
Cancel
Save