@lucid-softworks/promise-all-keyed
v0.1.0
Published
Resolve keyed promise-like values while preserving their object shape.
Maintainers
Readme
@lucid-softworks/promise-all-keyed
Resolve keyed promise-like values in parallel while preserving their object shape. The behavior follows the Stage 3 TC39 Await Dictionary proposal.
Ponyfill
The default entry point is side-effect-free and does not modify Promise.
import { allKeyed } from "@lucid-softworks/promise-all-keyed";
const { shape, color, mass } = await allKeyed({
shape: Promise.resolve("circle"),
color: Promise.resolve("blue"),
mass: Promise.resolve(12),
});
console.log({ shape, color, mass });Polyfill
Import the explicit polyfill entry point once before using
Promise.allKeyed. It leaves an existing implementation unchanged.
import "@lucid-softworks/promise-all-keyed/polyfill";
const { shape, color, mass } = await Promise.allKeyed({
shape: Promise.resolve("circle"),
color: Promise.resolve("blue"),
mass: Promise.resolve(12),
});
console.log({ shape, color, mass });The result contains the input's own enumerable string and symbol keys in the
same order. Like the proposal, it is a new mutable object with a null
prototype. A rejected input rejects the returned promise.
