Skip to content
Helpers for using promise.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
src
.eslintignore
.gitignore
.nvmrc
LICENSE
README.md
jest.config.js
package.json
tsconfig.json
tslint.json
yarn.lock

README.md

Promise S.O.S

npm package npm downloads CircleCI Coverage Status DevDependencies Dependencies Codacy Badge CII Best Practices Conventional Commits Types: TypeScript License: MIT

A typed 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

You can’t perform that action at this time.