Javascript Array seqAsync(promiseTask, callback)

Description

Javascript Array seqAsync(promiseTask, callback)


Array.prototype.seqAsync = function(promiseTask, callback) {
  var p = promiseTask(this.shift()); 

  this.forEach(function(element){
    p = p.then(function(){ return promiseTask(element); }); 
  });/* w  ww  . j  a v  a  2 s  .co  m*/
  p.then(callback);
  return p;
};



PreviousNext

Related