# es6-promise-try

> Promise.try shim for ES6 Promises

Latest version **1.0.2** (published 2016-08-16) · WTFPL license · 0 weekly downloads

## Install

```sh
npm install es6-promise-try
pnpm add es6-promise-try
yarn add es6-promise-try
bun add es6-promise-try
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2016-08-16 |
| First published | 2016-04-17 |
| Weekly downloads | 0 |
| License | WTFPL |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Sven Slootweg |
| Maintainers | joepie91 |
| Keywords | es6, promises, shim |

## Links

- npm: https://www.npmjs.com/package/es6-promise-try
- Repository: http://git.cryto.net/joepie91/node-es6-promise-try
- npm.io page: https://npm.io/package/es6-promise-try

## Alternatives

- [promise-throttle](https://npm.io/package/promise-throttle.md) — 44.2K weekly downloads
- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2016-08-16
- 1.0.1 — 2016-08-16
- 1.0.0 — 2016-08-16
- 0.0.1 — 2016-04-17

## README

# es6-promise-try

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.

__This module requires ES6 Promises to be available in your environment.__ If you are targeting a platform that doesn't (always) provide ES6 Promises natively, you will need to use a polyfill like [`es6-promise`](https://www.npmjs.com/package/es6-promise).

## License

[WTFPL](http://www.wtfpl.net/txt/copying/) or [CC0](https://creativecommons.org/publicdomain/zero/1.0/), whichever you prefer. A donation and/or attribution are appreciated, but not required.

## Donate

Maintaining open-source projects takes a lot of time, and the more donations I receive, the more time I can dedicate to open-source. If this module is useful to you, consider [making a donation](http://cryto.net/~joepie91/donate.html)!

You can donate using Bitcoin, PayPal, Flattr, cash-in-mail, SEPA transfers, and pretty much anything else. Thank you!

## Contributing

Pull requests welcome. Please make sure your modifications are in line with the overall code style, and ensure that you're editing the files in `src/`, not those in `lib/`.

Build tool of choice is `gulp`; simply run `gulp` while developing, and it will watch for changes.

Be aware that by making a pull request, you agree to release your modifications under the licenses stated above.

## Usage

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

### 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).

---
_Source: https://npm.io/package/es6-promise-try · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
