https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Promise#%E7%A4%BA%E4%BE%8B
主要问题,解决异步回调的烦人写法

Race

两个异步任务同时执行,听从先有反馈的

  1. const promise1 = new Promise((resolve, reject) => {
  2. setTimeout(resolve, 500, 'one');
  3. });
  4. const promise2 = new Promise((resolve, reject) => {
  5. setTimeout(resolve, 100, 'two');
  6. });
  7. Promise.race([promise1, promise2]).then((value) => {
  8. console.log(value);
  9. // Both resolve, but promise2 is faster
  10. });
  11. // expected output: "two"