Utility class to simplify use of timers created by setTimeout.
npm install chronoman
Install component:
npm install -g component
Then:
component install gamtiq/chronoman
Use dist/chronoman.js
or dist/chronoman.min.js
(minified version).
var Timer = require("chronoman");
define(["path/to/dist/chronoman.js"], function(Timer) {
...
});
<script type="text/javascript" src="path/to/dist/chronoman.js"></script>
<script type="text/javascript">
// сhronoman is available via Chronoman field of window object
var Timer = Chronoman;
...
</script>
var nI = 0;
var tmrOne = new Timer({
period: 1000,
action: function(timer) {
console.log("---> Timer one. ", timer); // timer is undefined because passToAction is false by default
}
});
var tmrTwo = new Timer();
tmrTwo.setPeriod(2000)
.setRecurrent(true)
.setPassToAction(true)
.setAction(function(timer) {
nI ;
console.log("Timer two. #", nI, timer);
tmrOne.setActive(! tmrOne.isActive());
if (nI === 10) {
timer.stop();
}
});
tmrTwo.start();
See doc
folder.
This module is inspired by qooxdoo's qx.event.Timer
class.
MIT