JavaScript Promise迷你书(中文版).......................................................................................... 33 Promise.all .............................................................................................. ........................................................................................ 108 Promise.all .............................................................................................. Promise#then 这种写法表示的是 Promise的实例对象的 then 这一方法。 • 对象方法都采用 object.method 的形式。 ◦ 这沿用了JavaScript中的使用方式, Promise.all 表示的是一个静态方法。 这部分内容主要讲述的是对正文部分的补充说明。 本书源代码/License 本书中示例代码都可以在GitHub上找到。 本书采用 AsciiDoc6 格式编写。0 码力 | 112 页 | 1010.02 KB | 1 年前3
JavaScript Promiseの本 v2......................................................................................... 37 Promise.all .............................................................................................. ......................................................................................... 134 Promise.all .............................................................................................. スオブジェクトの then メソッドを示しています。 • オブジェクトメソッドを object.method という表記で示す。 ◦ これはJavaScriptの意味そのままで、 Promise.all なら静的メソッドを示していま す。 この部分には文章についての補足が書かれています。 本書のソースコード/ライセンス この書籍に登場するサンプルのソースコード また その文章のソースコードは全てGitHubか0 码力 | 137 页 | 1.17 MB | 1 年前3
JavaScript Promiseの本 v1......................................................................................... 33 Promise.all .............................................................................................. ........................................................................................ 112 Promise.all .............................................................................................. ジェクトの then というメソッドを示しています。 • オブジェクトメソッドを object.method という表記で示す。 ◦ これはJavaScriptの意味そのままで、 Promise.all なら静的メソッドのことを示して います。 この部分には文章についての補足が書かれています。 本書のソースコード/ライセンス この書籍に登場するサンプルのソースコード また その文章のソースコードは全てGitHubか0 码力 | 115 页 | 1.06 MB | 1 年前3
阮一峰 《ECMAScript 6入门》 第三版catch 方法用来捕获,前一个 catch 方法抛出的错误。 Promise.all() Promise 对象 348 Promise.all 方法用于将多个 Promise 实例,包装成一个新的 Promise 实例。 var p = Promise.all([p1, p2, p3]); 上面代码中, Promise.all 方法接受一个数组作为参数, p1 、 p2 、 p3 p3 都是 Promise 实例,如果不是,就会先调用下面讲到的 Promise.resolve 方法,将参 数转为 Promise 实例,再进一步处理。( Promise.all 方法的参数可以不是数 组,但必须具有 Iterator 接口,且返回的每个成员都是 Promise 实例。) p 的状态由 p1 、 p2 、 p3 决定,分成两种情况。 (1)只有 p1 、 p2 promises = [2, 3, 5, 7, 11, 13].map(function (id) { return getJSON('/post/' + id + ".json"); }); Promise.all(promises).then(function (posts) { // ... }).catch(function(reason){ // ... }); 上面代码中,0 码力 | 679 页 | 2.66 MB | 1 年前3
ES6 Tutorial....................................................................................... 312 promise.all() ............................................................................................ are discussed below in detail: promise.all() This method can be useful for aggregating the results of multiple promises. Syntax The syntax for the promise.all() method is mentioned below, where where, iterable is an iterable object. E.g. Array. Promise.all(iterable); Example The example given below executes an array of asynchronous operations [add_positivenos_async(10,20),add_positivenos_async(300 码力 | 435 页 | 4.00 MB | 1 年前3
ThinkJS 2.0 中文文档��� catch ��������� ��� �� async/await ������������������������������������� ����������� Promise.all ���� ������ export default class extends think.controller.base { async indexAction(){ console.log(err.stack); }) } }) JavaScript ���� ����� p1 � p2 ���������� Promise.all ��� 2 �������������� ����������������� ThinkJS ������������������������������������� common = this.getServiceData1(); let p2 = this.getAPIData2(); let [p1Data, p2Data] = await Promise.all([p1, p2]); } } JavaScript ���� �� ���� drwxr-xr-x 5 welefen staff 170 Aug 18 15:550 码力 | 238 页 | 1.87 MB | 1 年前3
ThinkJS 2.1 Documentationexecution efficiency. For this, you can use Promise.all to implement it. p1 and p2 are processed parallelly and then get both data by using Promise.all . If your projects need to output data like = this.getServiceData1(); let p2 = this.getAPIData2(); let [p1Data, p2Data] = await Promise.all([p1, p2]); } } JavaScript Output Images export default class extends think.controller.base0 码力 | 148 页 | 1.69 MB | 1 年前3
ThinkJS 2.2 Documentationmostly you want to excute parallely to have higher execution efficiency. For this, you can use Promise.all to implement it. export default class extends think.controller.base { async indexAction(){ getAPIData2(); let [p1Data, p2Data] = await Promise.all([p1, p2]); } } p1 and p2 are processed parallelly and then get both data by using Promise.all . If your projects need to output data like0 码力 | 156 页 | 2.62 MB | 1 年前3
ThinkJS 2.2 中文文档catch 里就不会有此 类的错误了。 并行处理 使用 async/await 来处理异步时,是串行执行的。但很多场景下我们需要并行处理,这样可以大 大提高执行效率,此时可以结合 Promise.all 来处理。 export default class extends think.controller.base { async indexAction(){ let p1 let p2 = this.getAPIData2(); let [p1Data, p2Data] = await Promise.all([p1, p2]); } } 上面的代码 p1 和 p2 是并行处理的,然后用 Promise.all 来获取 2 个数据。这样一方面代码 是同步书写的,同时又不失并行处理的性能。 如何输出图片 项目中有时候要输出图片等类型的数据,可以通过下面的方式进行:0 码力 | 277 页 | 3.61 MB | 1 年前3
廖雪峰JavaScript教程除了串行执行若干异步任务外,Promise还可以并行执行异步任务。 试想一个页面聊天系统,我们需要从两个不同的URL分别获得用户的个人信息和好友列表,这两个任务 是可以并行执行的,用 Promise.all() 实现如下: 1. var p1 = new Promise(function (resolve, reject) { 2. setTimeout(resolve, 500, reject) { 5. setTimeout(resolve, 600, 'P2'); 6. }); 7. // 同时执行p1和p2,并在它们都完成后执行then: 8. Promise.all([p1, p2]).then(function (results) { 9. console.log(results); // 获得一个Array: ['P1', 'P2'] 100 码力 | 264 页 | 2.81 MB | 10 月前3
共 23 条
- 1
- 2
- 3













