24.1 概览
下面的函数通过 Promise 异步地返回结果:
function asyncFunc() {
    return new Promise(
        function (resolve, reject) {
            resolve(value); // success
            ···
            reject(error); // failure
        });
}
像下面这样调用 asyncFunc() :
asyncFunc()
.then(value => { /* success */ })
.catch(error => { /* failure */ });
24.1.1 处理 Promise 数组
Promise.all() 使你能够应对 Promise 数组。
例如,可以通过 Array 的方法 map() 创建一个 Promise 数组:
let fileUrls = [
    'http://example.com/file1.txt',
    'http://example.com/file2.txt'
];
let promisedTexts = fileUrls.map(httpGet); // Array of Promises
如果对这个数组调用 Promise.all() ,那么在所有 Promise 成功完成之后,会得到一个值数组:
Promise.all(promisedTexts)
// Success
.then(texts => {
    for (let text of texts) {
        console.log(text);
    }
})
// Failure
.catch(reason => {
    // Receives first rejection among `promisedTexts`
});