JavaScript Promise迷你书(中文版)20 Promise#catch ..... 28 专栏: 每次调用then都会返回一个新创建的promise对象 ..... 30 Promise和数组 ..... 33 Promise.all ..... 37 Promise.race ..... 39 then or catch? ..... 41 Chapter.3 - Promise测试 ..... 43 基本测试 Promise#then ..... 107 Promise#catch ..... 107 Promise.resolve ..... 108 Promise.reject ..... 108 Promise.all ..... 109 Promise.race ..... 109 用語集 ..... 110 参考网站 ..... 110 关于作者 ..... 111 关于译者 .. Promise#then 这种写法表示的是 Promise 的实例对象的 then 这一方法。 - 对象方法都采用 object.method 的形式。 。这沿用了JavaScript中的使用方式,Promise.all 表示的是一个静态方法。 0 码力 | 112 页 | 1010.02 KB | 2 年前3
JavaScript Promiseの本 v2Promise#finally ..... 32 コラム: thenは常に新しいpromiseオブジェクトを返す ..... 34 Promiseと配列 ..... 37 Promise.all ..... 42 Promise.race ..... 45 then or catch? ..... 46 Chapter.3 - Promiseのテスト ..... 49 Promise#then 131 Promise#catch 132 Promise#finally 132 Promise.resolve 133 Promise.reject 134 Promise.all 134 Promise.race 135 用語集 135 参考サイト 136 著者について 136 著者へのメッセージ/おまけ 137 This book has been という表記は、Promiseのインスタンスオブジェクトの then メソッドを示しています。 ・オブジェクトメソッドを object.method という表記で示す。 これはJavaScriptの意味そのままで、Promise.all なら静的メソッドを示しています。 0 码力 | 137 页 | 1.17 MB | 2 年前3
JavaScript Promiseの本 v121 Promise#catch ..... 29 コラム: thenは常に新しいpromiseオブジェクトを返す ..... 31 Promiseと配列 ..... 33 Promise.all ..... 38 Promise.race ..... 41 then or catch? ..... 42 Chapter.3 - Promiseのテスト ..... 45 Promise#then ..... 110 Promise#catch ..... 110 Promise.resolve ..... 111 Promise.reject ..... 112 Promise.all ..... 112 Promise.race ..... 113 用語集 ..... 113 参考サイト ..... 114 著者について ..... 114 著者へのメッセージ/おまけ という表記は、Promiseのインスタンスオブジェクトの then というメソッドを示しています。 ・オブジェクトメソッドを object.method という表記で示す。 これはJavaScriptの意味そのままで、Promise.all なら静的メソッドのことを示しています。  Promise.all 方法用于将多个 Promise 实例,包装成一个新的 Promise 实例。 var p = Promise.all([p1, p2, p3]); 上面代码中,Promise.all 方法接受一个数组作为参数,p1、p2、p3 都是 Promise 实例,如果不是,就会先调用下面讲到的 实例,如果不是,就会先调用下面讲到的 Promise.resolve 方法,将参数转为 Promise 实例,再进一步处理。(Promise.all 方法的参数可以不是数组,但必须具有 Iterator 接口,且返回的每个成员都是 Promise 实例。) p 的状态由 p1 、 p2 、 p3 决定,分成两种情况。 (1)只有 p1 、 p2 、 p3 的状态都变成 fulfilled , p 的状态才会变成 11, 13].map(function (id) { return getJSON('/post/' + id + ".json"); }); Promise.all(promises).then(function (posts) { // ... }).catch(function(reason) { // ... }); 上面代码中,promises0 码力 | 679 页 | 2.66 MB | 2 年前3
ES6 TutorialES6 – PROMISES ..... 311 Promise Syntax ..... 311 Promises Chaining ..... 312 promise.all() ..... 314 promise.race() ..... 315 Understanding Callback ..... 317 Unders 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(iterables); ## Example The example given below executes an array of asynchronous operations [add_positivenos_async(10,20),add_positivenos_async(300 码力 | 435 页 | 4.00 MB | 2 年前3
ThinkJS 2.2 Documentationmostly you want to execute parallelly 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 ## Output Images If your projects need to output0 码力 | 156 页 | 2.62 MB | 2 年前3
ThinkJS 2.0 中文文档return,这样 catch 里就不会有此类的错误了。 ## 并行处理 使用 async/await 来处理异步时,是串行执行的。但很多场景下我们需要并行处理,这样可以大大提高执行效率,此时可以结合 Promise.all 来处理。 export default class extends think.controller.base { async indexAction() { let p2 = this.getAPIData2(); let [p1Data, p2Data] = await Promise.all([p1, p2]); } } JavaScript 上面的代码 p1 和 p2 是并行处理的,然后用 Promise.all 来获取 2 个数据。这样一方面代码是同步书写的,同时又不失并行处理的性能。 ## 进阶应用 ## 模块 ThinkJS0 码力 | 238 页 | 1.87 MB | 2 年前3
ThinkJS 2.2 中文文档catch 里就不会有此类的错误了。 ## 并行处理 使用 `async/await` 来处理异步时,是串行执行的。但很多场景下我们需要并行处理,这样可以大大提高执行效率,此时可以结合 `Promise.all` 来处理。 export default class extends think.controller.base { async indexAction() { let p1 = this getServiceData1(); let p2 = this.getAPIData2(); let [p1Data, p2Data] = await Promise.all([p1, p2]); } 上面的代码 p1 和 p2 是并行处理的,然后用 Promise.all 来获取 2 个数据。这样一方面代码是同步书写的,同时又不失并行处理的性能。 ## 如何输出图片 项目中有时候要输出图片等类型的数据,可以通过下面的方式进行:0 码力 | 277 页 | 3.61 MB | 2 年前3
ThinkJS 2.1 Documentationmostly you want to execute parallelly to have higher execution efficiency. For this, you can use Promise.all to implement it. export default class extends think.controller.base { async indexAction() this.getServiceData1(); let p2 = this.getAPIData2(); let [p1Data, p2Data] = await Promise.all([p1, p2]); } } p1 and p2 are processed parallelly and then get both data by using Promise0 码力 | 148 页 | 1.69 MB | 2 年前3
新语⾔,新思维 解读⼀个并发问题的多种实现 - 陶召胜}; const target = 10000000; // 求1-target的和 25 // 异步执行多个任务,然后(then)收集所有任务的计算结果(results) 26 27 // Promise.all([calculate(1, target / 2), calculate(target / 2 + 1, target)]).then(function(results) { 28 29 300 码力 | 42 页 | 9.85 MB | 2 年前3
共 22 条
- 1
- 2
- 3













