Skip to content

Commit

Permalink
-reset - code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
igorshevach committed Sep 6, 2016
1 parent 821ed7c commit 46797ad
Showing 1 changed file with 14 additions and 27 deletions.
41 changes: 14 additions & 27 deletions lib/playlistGenerator/PlaylistGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,34 +493,21 @@ PlaylistGenerator.prototype.reset = function() {
}
if(that.resetting){
that.logger.warn("reset. already resetting");
return that.resetting.promise;
return that.resetting;
}
that.resetting = Q.defer();
try {
setPlayList.call(that,new Playlist(that.loggerInfo));
var endReset = function(err){
that.logger.warn("reset. done %j", err ? ErrorUtils.error2string(err) : 'ok' );
if(err) {
that.resetting.reject(err);
} else {
that.resetting.resolve();
}
delete that.resetting;
};

that.startPromise.promise
.then(function () {
return persistPlayList.call(that)
})
.then(function () {
return finalizeStart.call(that);
})
.then(endReset)
.catch(endReset);
} catch(err){
endReset(err);
}
return that.resetting.promise;
setPlayList.call(that,new Playlist(that.loggerInfo));

that.resetting = that.startPromise.promise
.then(function () {
return persistPlayList.call(that)
})
.then(function () {
return finalizeStart.call(that);
})
.finally( () => {
delete that.resetting
});
return that.resetting;
};


Expand Down

0 comments on commit 46797ad

Please sign in to comment.