tc39 / proposal-await-dictionary

A proposal to add Promise.ownProperties(), Promise.fromEntries() to ECMAScript
MIT License
86 stars 4 forks source link

`Object.resolveValues` and `Object.settleValues` #16

Closed fisker closed 1 year ago

fisker commented 1 year ago
const {
  one, // 1
  two, // 2
} = await Object.resolveValues({
  foo: Promise.resolve(1),
  bar: Promise.resolve(2),
});
const {
  one, // { status: 'fulfilled', value: 1 }
  two, // { status: 'rejected', reason: 2 }
} = await Object.settleValues({
  one: Promise.resolve(1),
  two: Promise.reject(2),
});
ljharb commented 1 year ago

It seems weird to have these on Object instead of Promise, since they produce a Promise, not an Object.

zloirock commented 1 year ago

It does not solve problems that should solve this proposal and it could cause many new potential bugs - for example, order with integer keys.

Or this is a bug in the names of keys in the first example?

ljharb commented 1 year ago

integer keys have a defined ordering in object keys; can you elaborate?

zloirock commented 1 year ago

(the first example with integer key)

const {
  one,
  two,
} = await Object.resolveValues({
  foo: Promise.resolve(1),
  1: Promise.resolve(2),
});

How should it work?

ljharb commented 1 year ago

oh, in that case the example's just wrong :-) it'd need to be:

const {
  1: one,
  foo: two,
} = await Object.resolveValues({
  foo: Promise.resolve(1),
  1: Promise.resolve(2),
});

(depending on which was meant to be which)

zloirock commented 1 year ago

In this case, it's just a name option for #7.

ljharb commented 1 year ago

True enough.