Created
March 10, 2012 19:38
-
-
Save lele85/2012641 to your computer and use it in GitHub Desktop.
Pomodoro in nodeJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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