Skip to content

Commit

Permalink
Make calls to phantomjs sequential.
Browse files Browse the repository at this point in the history
  • Loading branch information
vinvol committed Apr 6, 2015
1 parent c5da4f4 commit 33e6b2d
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions tasks/lib/phantomas.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,23 @@ Phantomas.prototype.createIndexHtml = function( results ) {
* @tested
*/
Phantomas.prototype.executePhantomas = function() {
var runs = [];
var responses = [],
queue,
gatherResponses = function( response ) {
responses.push( response );
return responses;
};


return new Promise( function( resolve ) {
var options;
var options,
url = this.options.url,
runPhantomas = function() {
return phantomas(
url,
options
).then( gatherResponses );
};

this.grunt.log.verbose.writeln(
'Executing phantomas ( ' + this.options.numberOfRuns + ' times ) with following parameters:\n' +
Expand All @@ -319,16 +332,13 @@ Phantomas.prototype.executePhantomas = function() {
options[ 'film-strip-dir' ] = this.imagePath + this.timestamp;
}

runs.push(
phantomas(
this.options.url,
options
)
);
if ( i === 0 ) {
queue = runPhantomas();
} else {
queue = queue.then( runPhantomas );
}
}

Promise.settle( runs )
.then( resolve )
queue.then( resolve )
.catch( function( e ) {
console.log( e );
} );
Expand Down

0 comments on commit 33e6b2d

Please sign in to comment.