spreadprom
v1.2.4
Published
A tiny library for making promises spreadable
Downloads
8
Readme
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 }