Skip to content

pbxx/spreadprom

Repository files navigation

Build status npm version

spreadprom

A tiny library for making promises spreadable...

Installation

npm install spreadprom

Usage

const { sprom } = require("spreadprom")
// or
import sprom from "spreadprom"

Use sprom to gracefully catch promise errors without try-catch blocks:

var [err, result] = await sprom( myPromise() )
if ( err ) { throw err }

// or

var myItem = [ ...await sprom( myPromise() ) ]
//  => [err, result]
if ( myItem[0] ) { throw myItem[0] }

Use included function osprom (short for object-sprom) to resolve into an object instead:

const { sprom, osprom } = require("spreadprom")
// or
import { sprom, osprom } from "spreadprom"

const myItem = await osprom( myPromise() )
// => {err, result}
if ( myItem.err ) { throw myItem.err }

About

A tiny library for making promises spreadable

Resources

License

Stars

Watchers

Forks

Packages

No packages published