@akolos/object-promise-all

A strongly typed Promise.all-like function that works on objects that has promises as some of its properties.

Usage no npm install needed!

<script type="module">
  import akolosObjectPromiseAll from 'https://cdn.skypack.dev/@akolos/object-promise-all';
</script>

README

object-promise-all

Like Promise.all, but works on all objects, not just arrays.

usage

import promiseAll from '@akolos/object-promise-all';

const obj = {
    prop1: Promise.resolve('prop1'),
    prop2: Promise.resolve('prop2'),
};

const resolved = await promiseAll(obj);
// resolved equals {prop1: 'prop1', prop2: 'prop2'}

The function also works with nested objects, arrays, and non-promise members.

const obj = {
    prop1: Promise.resolve('prop1'),
    arr: [
            Promise.resolve('prop2'),
            { prop3: Promise.resolve('prop3')},
    ],
     notAPromise: 'prop4',
};

const resolved = await objectPromiseAll(obj);
/*
{
    prop1: 'prop1',
    arr: ['prop2', {prop3: 'prop3'}],
    notAPromise: 'prop4',
}
*/