Utility class to simplify use of timers created by setTimeout
JavaScript Other
Fetching latest commit…
Cannot retrieve the latest commit at this time.

README.md

chronoman

Utility class to simplify use of timers created by setTimeout.

NPM version Build Status Built with Grunt

Installation

Node

npm install chronoman

JSPM

jspm install chronoman

Bower

bower install chronoman

Jam

jam install chronoman

AMD, <script>

Use dist/chronoman.js or dist/chronoman.min.js (minified version).

Usage

ECMAScript 6/2015

import Timer from "chronoman";

Node, JSPM

var Timer = require("chronoman");

Duo

var Timer = require("gamtiq/chronoman");

JSPM

System.import("chronoman").then(function(Timer) {
    ...
});

Jam

require(["chronoman"], function(Timer) {
    ...
});

AMD

define(["path/to/dist/chronoman.js"], function(Timer) {
    ...
});

Bower, <script>

<!-- Use bower_components/chronoman/dist/chronoman.js if the library was installed by Bower -->
<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>

Example

var nI = 0;

var tmrOne = new Timer({
    period: 1000,
    action: function(timer) {
        console.log("---> Timer one. ", timer);
        if (! tmrThree.isActive()) {
            tmrThree.start();
        }
    }
});

var tmrTwo = new Timer();
tmrTwo.setPeriod(2000)
    .setRepeatQty(9)
    .setPassToAction(true)
    .setAction(function(timer) {
        nI++;
        console.log("Timer two. #", nI, timer);
        tmrOne.setActive(nI % 2 === 1);
    });

var tmrThree = new Timer()
                    .setPeriod(3000)
                    .setRepeatTest(function() {
                        return tmrTwo.isActive();
                    });
tmrThree.onExecute = function() {
    console.log("* Timer three. #", this.getExecutionQty() + 1);
};

tmrTwo.start();

API

See doc folder.

Inspiration

This module is inspired by qooxdoo's qx.event.Timer class.

Licence

Copyright (c) 2013-2016 Denis Sikuler
Licensed under the MIT license.