The realization Promise.all

Simple implementation of Promise.all

Promise.all = arr => {
    The aResult the let = [];     // for storing execution results of each return 
    return  new new _Promise ( function (Resolve, Reject) {
      let i = 0;
      Next ();     // start function sequentially executed array (important) 
      function Next () {
        arr[i].then(function (res) {
          aResult.push (RES);     // store the results of each obtained 
          I ++ ;
           IF (arr.length == I) {     // If the function in the function array have been performed, then Resolve 
            Resolve (The aResult);
          } else {
            next();
          }
        })
      }
    })
  };

Guess you like

Origin www.cnblogs.com/ygunoil/p/12124486.html