mirror of https://github.com/lukechilds/rollup.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
495 B
28 lines
495 B
var Promise = require( 'sander' ).Promise;
|
|
|
|
module.exports = function sequence ( arr, callback ) {
|
|
var len = arr.length;
|
|
var results = new Array( len );
|
|
|
|
var promise = Promise.resolve();
|
|
|
|
function next ( i ) {
|
|
return promise
|
|
.then( function () {
|
|
return callback( arr[i], i );
|
|
})
|
|
.then( function ( result ) {
|
|
results[i] = result;
|
|
});
|
|
}
|
|
|
|
var i;
|
|
|
|
for ( i = 0; i < len; i += 1 ) {
|
|
promise = next( i );
|
|
}
|
|
|
|
return promise.then( function () {
|
|
return results;
|
|
});
|
|
};
|
|
|