Skip to main content

@idearium/safe-promise

Makes working with promises safer.

Installation

$ yarn add -E @idearium/safe-promise

Beta installation

If you need to install a beta version, you can:

$ yarn add -E @idearium/safe-promise@beta

Usage

safePromise

To use safePromise, import it from @idearium/safe-promise.

import { safePromise } from '@idearium/safe-promise';

This will take a promise and always use resolve to return a result in the format [err, result].

This provides the ability to use async/wait without try/catch blocks.

Use it like so:

const [err, result] = await safePromise(someAsyncFn);

if (err) {
return console.log(err);
}

// Do other stuff knowing an error didn't occur.