Why isn't `Promise.all()` overloaded?
Tab Atkins Jr.
jackalmage at gmail.com
Fri Aug 10 22:02:57 UTC 2018
On Fri, Aug 10, 2018 at 2:30 PM Jacob Pratt <jhprattdev at gmail.com> wrote:
> This is potentially a very simple question, `Promise.all()` takes a single iterable as a parameter. Is there any particularly reason it wasn't overloaded to allow passing multiple parameters (and use `...arguments`)? Of course, the only difference is the creation of an array, but it is an array that doesn't need to be created.
API complexity - Promise.all()'s promise resolves to an array of
resolved values. How would multiple input iterables be reflected here?
Just concatenated together? More straightforward and predictable to
just ask the user to concatenate things on the input side.
Also, Promise.all(), following the example of other promise methods,
doesn't require the values in the input array to be promises; it just
Promise.resolve()'s all of them, so you can pass in non-Promise values
as well. With a "multiple input arguments" API shape, it's less clear
that `Promise.all("foo", "bar")` is wrong, for instance (it would
treat each of them as a 3-element array of characters). With the
current design you usually have to put in a literal , so it's easier
to remember the API shape.
More information about the es-discuss