0.2.0 • Published 5 years ago

promise-sos v0.2.0

Weekly downloads
35
License
MIT
Repository
github
Last release
5 years ago

Promise SOS

Build Status License: MIT

A library that provides utilities for working with promises.

Installation

npm i promise-sos

Usage

  • promiseAllObject

    Helper function which receives an object with a promise in each property and returns a promise that resolves to an object with the same properties and the resolved values of the promises.

    import { promiseAllObject } from 'promise-sos';
    
    const promisesObject = {
      promiseA: Promise.resolve('resolved promiseA'),
      promiseB: Promise.resolve('resolved promiseB'),
      1: 'resolved',
      '1234-5678': 1234
    };
    
    const result = await promiseAllObject(promisesObject);
    
    console.log(result);
    
    // {
    //   'promiseA': 'resolved promiseA',
    //   'promiseB': 'resolved promiseB',
    //   1: 'resolved',
    //   '1234-5678': 1234
    // }
    import { promiseAllObject } from 'promise-sos';
    
    const promisesObject = {
      promiseA: Promise.reject(new Error('rejected promiseA')),
      promiseB: Promise.resolve('resolved promiseB')
    };
    
    try {
      const result = await promiseAllObject(promisesObject);
    } catch (error) {
      console.log(error);
    }

License

MIT