0.1.0 • Published 5 years ago
@aberration/promise-map v0.1.0
Keyed Promise.all
Promise.all implementation that takes an object literal
npm i @aberration/promise-map
Useful for destructuring results, with the build in Promise.all you have to rely on the order the promises were added to the array. This is problematic if you want to add
import { all } from "@aberration/promise-map";
let fetchOptionalResource = false;
let requests = {
resource: fetch("/resource"),
optionalResource: fetchOptionalResource ? fetch("/resource") : null
};
const { resource, optionalResource } = await all(requests);
all
Promise.all implementation that takes an object literal instead of an array. If a value is not Promise like the value is returned.
Parameters
obj
Object The key value pair of promises to be awaited
0.1.0
5 years ago