chronoman
Utility class to simplify use of timers created by setTimeout
.
Features
- Support for one-time (like
setTimeout
) or recurrent (likesetInterval
) timers. - It is possible to repeat action indefinitely (
recurrent
property), specified number of times (repeatQty
property) or depending on result of control function (repeatTest
property). - Time period (timeout) can be: a fixed value, a random value, an item selected from a list depending on action's execution number, or a value returned from specified function.
- Action that is called can be a function or an object specifying function and its call's context.
- Action result is saved in timer's field for further access.
- Timer's start time, stop time and action execution times are saved in
startTime
,stopTime
andexecuteTime
properties correspondingly.
var timer = period: 100 200 300 400 500 start: 100 end: 500 repeatQty: 100 passToAction: true { console; } active: true;...timer;
Installation
Node
npm install chronoman
Bower
bower install chronoman
AMD, <script>
Use dist/chronoman.js
or dist/chronoman.min.js
(minified version).
Usage
ECMAScript 6/2015
;
Node
var Timer = Timer;
AMD
;
Bower, <script>
<!-- Use bower_components/chronoman/dist/chronoman.js if the library was installed by Bower -->
Example
var tmrOne = { return 1000 + timer * 100; } { console; if ! tmrThree tmrThreestart; }; var tmrTwo = ;tmrTwo ; var tmrThree = ;tmrThree { console;}; tmrTwostart;
See test/chronoman.js
for additional examples.
API
See doc
folder.
Related projects
Inspiration
This module is inspired by qooxdoo's qx.event.Timer
class.
Licence
Copyright (c) 2013-2020 Denis Sikuler
Licensed under the MIT license.