# promise-try

> wraps a synchronously executing function and returns a promise

Latest version **1.0.1** (published 2015-09-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install promise-try
pnpm add promise-try
yarn add promise-try
bun add 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.1 |
| Published | 2015-09-19 |
| First published | 2015-09-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Will Binns-Smith |
| Maintainers | wbinnssmith |
| Keywords | promise |

## Links

- npm: https://www.npmjs.com/package/promise-try
- Repository: https://github.com/wbinnssmith/promise-try
- Homepage: https://github.com/wbinnssmith/promise-try#readme
- Issues: https://github.com/wbinnssmith/promise-try/issues
- npm.io page: https://npm.io/package/promise-try

## Alternatives

- [@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
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2015-09-19

## README

# promise-try

Wraps a synchronously executing function and returns a promise that resolves to its return value and rejects its exceptions. API-compatible with [Bluebird](https://github.com/petkaantonov/bluebird)'s `Promise.try`.

Accepts an alternate Promise implementation as input if the environment doesn't natively support them.

This module is meant to be a convenient standalone implementation of a Promise utility, but it doesn't provide an alternate Promise constructor and is less than 500 bytes minified and gzipped.

## API

```js
function promiseTry(fn, args, ctx, Promise)
```

`fn` - a synchronously executed function that may return or throw synchronously. This will be wrapped and returned as a promise.

`args` - arguments to applied to the passed function. If not an array, it will be passed as a single argument to the function. If an array, it will be spread across the function's parameters.

<small>I personally don't like this API since one could never achieve passing the function a single argument that is an array, but this is here for compatibility with bluebird. Instead, one could just use something like `.bind(null, [1, 2, 3])` when passing the function.</small>

`ctx` - the context (`this`) to be used when the function is executed.

<small>Again, one could just use `.bind(ctx)` on the original function</small>

`Promise` an alternate Promise implementation to use (perhaps if a global one doesn't exist)

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