Skip to content

Instantly share code, notes, and snippets.

@lele85
Created March 10, 2012 19:38
Show Gist options
  • Save lele85/2012641 to your computer and use it in GitHub Desktop.
Save lele85/2012641 to your computer and use it in GitHub Desktop.
Pomodoro in nodeJS
function createPomodoro(params) {
var validOrDefaultDuration = function(duration){
var DEFAULT_POMODORO_DURATION = 1000;
return (duration !== undefined) ? duration : DEFAULT_POMODORO_DURATION;
}
var _started = false;
var _finished = false;
var _duration = validOrDefaultDuration(params.duration);
var pomodoro = {};
var stop = function(){
_started = false;
_finished = true;
}
var start = function(callerPomodoroFinishedCb){
_started = true;
setTimeout(function(){
stop();
if (callerPomodoroFinishedCb !== undefined){
callerPomodoroFinishedCb();
}
}
,_duration);
}
var isRunning = function(){
return _started === true;
}
var isFinished = function(){
return _finished === true;
}
var duration = function(){
return (_duration/1000).toString() + " sec";
}
//Public members of pomodoro
pomodoro.start = start;
pomodoro.isRunning = isRunning;
pomodoro.isFinished = isFinished
pomodoro.duration = duration;
return pomodoro;
};
exports.create = createPomodoro;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment