Tag: es6 promise

了解promise.race()用法

据我所知, promise有两种选择: promise.all() promise.race() 好的,我知道promise.all()作用。 它并行运行promises,然后.then为两个值提供成功解析的值。 这是一个例子: Promise.all([ $.ajax({ url: ‘test1.php’ }), $.ajax({ url: ‘test2.php’ }) ]) .then(([res1, res2]) => { // Both requests resolved }) .catch(error => { // Something went wrong }); 但是我不明白promise.race()应该做什么呢? 换句话说,不使用它有什么区别? 假设这个: $.ajax({ url: ‘test1.php’, async: true, success: function (data) { // This request resolved } }); $.ajax({ url: ‘test2.php’, […]