Socket
Book a DemoInstallSign in
Socket

promise-all-settled-by-key

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promise-all-settled-by-key

[![Build Status](https://travis-ci.org/Dobby89/promise-all-settled-by-key.svg)](https://travis-ci.org/Dobby89/promise-all-settled-by-key) [![Total Downloads](https://img.shields.io/npm/dt/promise-all-settled-by-key.svg)](https://www.npmjs.com/package/pro

1.0.3
latest
Source
npmnpm
Version published
Weekly downloads
2
-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

Promise All Settled By Key

Build Status Total Downloads Latest Release License

Returns a promise that resolves after all of the given promises have either resolved or rejected, with an object that contains the resolved status and value of each promise.

Why?

Promise.allSettled() returns promises in an array with no index or key, so you can't track what happened to which promise.

However, this package makes it possible to determine the outcome and value of specific promises because it returns each promise by key.

Installation

npm install promise-all-settled-by-key

Usage

import promiseAllSettledByKey from 'promise-all-settled-by-key';

const promiseMap = {
    theNumberThree: Promise.resolve(3),
    getFoo: new Promise((resolve, reject) => setTimeout(reject, 100, 'foo error'),
    nope: new Promise((resolve, reject) => setTimeout(reject, 100))
}

promiseAllSettledByKey(promiseMap).then(settled => {
    console.log(settled);
});

// Expected output
// {
//     theNumberThree: { resolved: true, value: 3 }
//     getFoo: { resolved: false, value: 'foo error' },
//     nope: { resolved: false, value: undefined }
// }

Resolved ONLY

You can set { onlyResolved = true } to return only the resolved promises.

promiseAllSettledByKey(promiseMap, { onlyResolved: true }).then(settled => {
    console.log(settled);
});

// Expected output
// {
//     theNumberThree: { resolved: true, value: 3 }
// }

Rejected ONLY

You can set { onlyRejected = true } to return only the rejected promises.

promiseAllSettledByKey(promiseMap, { onlyRejected: true }).then(settled => {
    console.log(settled);
});

// Expected output
// {
//     getFoo: { resolved: false, value: 'foo error' },
//     nope: { resolved: false, value: undefined }
// }

Keywords

promise.allSettled()

FAQs

Package last updated on 12 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.