Promise.all 中的 Thenables(ES6 和 Bluebird)

Thenables in Promise.all (ES6 and Bluebird)

这个安全装置有必要吗?

Promise.all([...].map((thenable) => Promise.resolve(thenable)));

向收集方法提供 thenable 是否可能且安全 - Promise.allPromise.race 等?有什么陷阱吗?

问题涉及 Bluebird,以及 polyfilled 和所有原生 ES6 promise 实现。

这不是必需的,应该由承诺实现本身完成:

The all function returns a new promise which is fulfilled with an array of fulfillment values for the passed promises, or rejects with the reason of the first passed promise that rejects. It resolves all elements of the passed iterable to promises as it runs this algorithm.

ES2015 Specification, paragraph 25.4.4.1 Promise.all ( iterable )

措辞更通俗易懂by MDN

If something passed in the iterable array is not a promise, it's converted to one by Promise.resolve.