Established name is Promise.properties

On Mon, 14 Oct 2019, 09:29 Cyril Auburtin, <[email protected]> wrote:

> maybe a naming like: `Promise.allObject`
>
> ```js
> Promise.allObject = obj => {
>   if (obj && !obj[Symbol.iterator]) {
>     return Promise.all(
>       Object.entries(obj).map(async ([k, v]) => [k, await v])
>     )
>       .then(Object.fromEntries);
>   }
>   return Promise.all(obj);
> }
>
> var delay = t => new Promise(r => setTimeout(r, t));
> console.time(1); console.log(await Promise.allObject({foo:
> delay(110).then(()=>1), bar: delay(120).then(()=>2)})); console.timeEnd(1)
> ```
>
> On Sun, Oct 13, 2019 at 8:55 PM Isiah Meadows <[email protected]>
> wrote:
>
>> Maybe Promise.join(object)? Also, if a map is passed (or any iterable),
>> it should be joined into a map.
>>
>> At the most basic level:
>>
>> ```js
>> Promise.join = (o) => {
>>     let isMap = o[Symbol.iterator] != null
>>     let ps = (
>>         isMap ? Array.from : Object.entries
>>     )(o)
>>     let ks = ps.map(p => p[0])
>>     return Promise.all(ps.map(p => p[1]))
>>     .then(vs => {
>>         let ps = vs.map((v, i) => [ks[i], v])
>>         return isMap
>>             ? new Map(ps)
>>             : Object.fromEntries(ps)
>>     })
>> }
>> ```
>>
>> On Sun, Oct 13, 2019 at 13:40 Cyril Auburtin <[email protected]>
>> wrote:
>>
>>> OP probably means he would like Promise.all to return an object as well,
>>> if an object if given
>>>
>>> It's possible to hack an object to be iterable, but Promise.all
>>> already return an array unfortunately
>>>
>>> On Sun, Oct 13, 2019 at 7:16 PM Boris Zbarsky <[email protected]> wrote:
>>>
>>>> On 10/12/19 12:52 AM, Jacob Bloom wrote:
>>>> > const responses = await Promise.all(requests);
>>>>
>>>> As opposed to:
>>>>
>>>>    const responses = await Primise.all(requests.values());
>>>>
>>>> which works right now?
>>>>
>>>> -Boris
>>>> _______________________________________________
>>>> es-discuss mailing list
>>>> [email protected]
>>>> https://mail.mozilla.org/listinfo/es-discuss
>>>>
>>> _______________________________________________
>>> es-discuss mailing list
>>> [email protected]
>>> https://mail.mozilla.org/listinfo/es-discuss
>>>
>> --
>> -----
>>
>> Isiah Meadows
>> [email protected]
>> www.isiahmeadows.com
>>
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to