promise ALL

promise.all = function(promises){
  return new Promise((resolve,reject)=>{
      let result = []
      let cnt = 0
      let len = promises.length
      for (let i=0; i{
          cnt++
          result[i] = res
          if(cnt === len) {
            resolve(result)
          }
        },(err)=>{
          reject(err)
        })
      }
  })
} 

promise.race = function (promises) {
  return new Promise((resolve, reject) => {
    for (let i = 0; i < promises.length; ++i) {
      promises[i].then(resolve, reject)
    }
  })
}


你可能感兴趣的:(promise ALL)