小程序PromiseAll定义

  var promiseAll = (funcs, callback) =>{
      var promises = []
      for(var i=0; i<funcs.length; i++){
        promises.push(new Promise(funcs[i]))
      }

      Promise.all(promises).then((result) => {
        callback(result);
      }).catch((error) => {
        console.log(error)
      });
    }

    promiseAll([
      (resolve, reject) =>{
        wx.getImageInfo({
          src: "http://static.xmappservice.com/pc/10001497943962163.jpg",
          success: function (res) {
            resolve(res);
          },
          fail: function(err){
            reject(err)
          }
        })
      },
      (resolve, reject) => {
        wx.getImageInfo({
          src: "http://static.xmappservice.com/pc/10041496645191972.jpg",
          success: function (res) {
            resolve(res);
          },
          fail: function(err){
            reject(err)
          }
        })
      }
    ], (res) =>{
      console.log(res)
    });

  

posted @ 2018-12-05 16:19  rubekid  阅读(817)  评论(0编辑  收藏  举报