Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

promise.allsettledkeyed Version Badge

github actions coverage License Downloads

npm badge

ES Proposal spec-compliant shim for Promise.allSettledKeyed. Invoke its "shim" method to shim Promise.allSettledKeyed if it is unavailable or noncompliant. Note: a global Promise must already exist: the es6-shim is recommended.

This package implements the es-shim API interface. It works in an ES3-supported environment that has Promise available globally, and complies with the proposed spec.

Promise.allSettledKeyed is like Promise.allSettled, but for a dictionary (a plain object) rather than an iterable: it awaits every enumerable own property value, and fulfills with a null-prototype object of the same keys, each mapped to a settlement result ({ status: 'fulfilled', value } or { status: 'rejected', reason }). As with Promise.allSettled, it never rejects on account of an input rejecting.

Most common usage:

var assert = require('assert');
var allSettledKeyed = require('promise.allsettledkeyed');

allSettledKeyed({
	shape: Promise.resolve('square'),
	color: Promise.reject('no color'),
	mass: 42
}).then(function (results) {
	assert.deepEqual(results.shape, { status: 'fulfilled', value: 'square' });
	assert.deepEqual(results.color, { status: 'rejected', reason: 'no color' });
	assert.deepEqual(results.mass, { status: 'fulfilled', value: 42 });
});

require('promise.allsettledkeyed/shim')(); // will be a no-op if not needed

Promise.allSettledKeyed({
	a: Promise.resolve(1),
	b: Promise.reject(2)
}).then(function (results) {
	assert.equal(results.a.status, 'fulfilled');
	assert.equal(results.a.value, 1);
	assert.equal(results.b.status, 'rejected');
	assert.equal(results.b.reason, 2);
});

The polyfill, implementation, and shim methods are available as separate entry points, per the es-shim API:

var getPolyfill = require('promise.allsettledkeyed/polyfill');
var implementation = require('promise.allsettledkeyed/implementation');
var shim = require('promise.allsettledkeyed/shim');

Tests

Simply clone the repo, npm install, and run npm test

About

ES spec-compliant shim for Promise.allSettledKeyed

Resources

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

Sponsor this project

Used by

Contributors

Languages