Javascript Array asyncForEach(asyncTask, callback)

Description

Javascript Array asyncForEach(asyncTask, callback)


Array.prototype.asyncForEach = function(asyncTask, callback) {
    var promises = [];
    this.forEach((element) => {/*from  www.j  a  v  a  2s .  com*/
      promises.push(new Promise(function(resolve, reject) {
          asyncTask(element, resolve);
        })
      );
    });
    var result = Promise.all(promises).then(() => {
      callback()
    });
};



PreviousNext

Related