Can Promise.all take in an array of all non-promis

2019-09-10 00:20发布

问题:

Promise.all resolves when all the promises in its array resolves, but there is an example where an element of the input array is not a promise https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise/all#Using_Promise.all

so i'm wondering, can Promise.all take in an array of all non-promise elements?

回答1:

Promise.all calls Promise.resolve on all of the argument elements before doing anything with them. For those that already are promises, nothing happens; for thenables, they'll be converted to a proper promise, and everything else will get wrapped in a fulfilled promise.