Stopwatch is a simple stopwatch-like timer that can emit events. It currently works only in seconds and will parse a string for seconds, minutes, and hours, and fractions thereof.
// Nodevar Stopwatch = Stopwatch;var stopwatch1 = '5m';var stopwatch2 = '30s';// Browservar Stopwatch = '0.5h';
var stopwatch = '5m';// Startstopwatchstart;// Stopstopwatch;// Pausestopwatch;// Restart from any spotstopwatch;
Stopwatch implements a classic event emitter. The node version uses the node event emitter and the browser version uses Oliver Caldwell's implementation of EventEmitter (thanks!). All events have the same name as the method that invokes them. An additional event
tick is also available which, as you might imagine, is called every second the stopwatch ticks.
var stopwatch = '5m';stopwatch;stopwatch;stopwatchstart; // Started!stopwatch; // Paused!stopwatch;stopwatch;// Tick!// Tick!
Stopwatch also have a few getters for time remaining, current time, and the max time, all in seconds. It also has an isRunning() call.
var stopwatch = '60s';stopwatch; // 0stopwatch; // 60// Start and wait 20 seconds...stopwatchstartstopwatch; // 40stopwatch; // true