All Projects → gamtiq → chronoman

gamtiq / chronoman

Licence: MIT license
Utility class to simplify use of timers created by setTimeout

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to chronoman

assign-one-project-github-action
Automatically add an issue or pull request to specific GitHub Project(s) when you create and/or label them.
Stars: ✭ 140 (+833.33%)
Mutual labels:  utility, management, action
audio-context-timers
A replacement for setInterval() and setTimeout() which works in unfocused windows.
Stars: ✭ 12 (-20%)
Mutual labels:  settimeout, setinterval, interval
timezz
With this plugin, you can easily make a stopwatch or timer on your site. Just init, style and enjoy.
Stars: ✭ 35 (+133.33%)
Mutual labels:  time, timer, repeat
sc2gears
The COMPLETE (!) source code of the Sc2gears universe (Sc2gears app + Sc2gears Database + web-based parsing engine - bundled in an Eclipse project).
Stars: ✭ 30 (+100%)
Mutual labels:  utility, management
timestampy
🕒 Bunch of utilities useful when working with UNIX timestamps
Stars: ✭ 21 (+40%)
Mutual labels:  utility, time
redtimer
RedTimer - Redmine Time Tracker
Stars: ✭ 59 (+293.33%)
Mutual labels:  utility, timer
Stopwatch
⏱️ Single-header C++11 RDTSCP clock and timing utilities released into the public domain.
Stars: ✭ 96 (+540%)
Mutual labels:  time, timer
Scelight
The source code of the Scelight project with all its modules.
Stars: ✭ 97 (+546.67%)
Mutual labels:  utility, management
action-sync-node-meta
GitHub Action that syncs package.json with the repository metadata.
Stars: ✭ 25 (+66.67%)
Mutual labels:  utility, action
Date And Time
A Minimalist DateTime utility for Node.js and the browser
Stars: ✭ 99 (+560%)
Mutual labels:  utility, time
timechange
Efficient Updating of Date-Times
Stars: ✭ 25 (+66.67%)
Mutual labels:  time, period
Timelite
Why is it 5 AM? Isn't there something simple I can use to track what I'm doing with all this time?
Stars: ✭ 201 (+1240%)
Mutual labels:  time, timer
React Timer Hook
React timer hook
Stars: ✭ 118 (+686.67%)
Mutual labels:  time, timer
Use Timer
A timer hook for React
Stars: ✭ 113 (+653.33%)
Mutual labels:  time, timer
STM32 TimerInterrupt
This library enables you to use Interrupt from Hardware Timers on an STM32F/L/H/G/WB/MP1-based board. These STM32F/L/H/G/WB/MP1 Hardware Timers, using Interrupt, still work even if other functions are blocking. Moreover, they are much more precise (certainly depending on clock frequency accuracy) than other software timers using millis() or micr…
Stars: ✭ 27 (+80%)
Mutual labels:  control, timer
SAMD TimerInterrupt
This library enables you to use Interrupt from Hardware Timers on an SAMD-based board. These SAMD Hardware Timers, using Interrupt, still work even if other functions are blocking. Moreover, they are much more precise (certainly depending on clock frequency accuracy) than other software timers using millis() or micros(). That's mandatory if you …
Stars: ✭ 28 (+86.67%)
Mutual labels:  control, timer
Uhubctl
uhubctl - USB hub per-port power control
Stars: ✭ 1,036 (+6806.67%)
Mutual labels:  utility, control
timer
Timing Events tied to @gamestdio/clock
Stars: ✭ 20 (+33.33%)
Mutual labels:  settimeout, setinterval
Iso8601
Ruby parser to work with ISO8601 dateTimes and durations — http://en.wikipedia.org/wiki/ISO_8601
Stars: ✭ 70 (+366.67%)
Mutual labels:  time, interval
Brein Time Utilities
Library which contains several time-dependent data and index structures (e.g., IntervalTree, BucketTimeSeries), as well as algorithms.
Stars: ✭ 94 (+526.67%)
Mutual labels:  time, interval

chronoman

NPM version Build Status Built with Grunt

Utility class to simplify use of timers created by setTimeout.

Features

  • Support for one-time (like setTimeout) or recurrent (like setInterval) 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 and executeTime properties correspondingly.
var timer = new Timer({
    period: [100, 200, 300, 400, 500, {start: 100, end: 500}],
    repeatQty: 100,
    passToAction: true,
    action: function(tmr) {
        console.log("#", tmr.getExecutionQty() + 1, ":", new Date());
    },
    active: true
});
...
timer.stop();

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

import Timer from "chronoman";

Node

var Timer = require("chronoman").Timer;

AMD

define(["path/to/dist/chronoman.js"], function(chronoman) {
    var Timer = chronoman.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.Timer;
    ...
</script>

Example

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

var tmrTwo = new Timer();
tmrTwo.setPeriod([2000, {start: 1000, end: 1500}])
    .setRepeatQty(9)
    .setPassToAction(true)
    .setAction({
        i: 0,
        execute: function(timer) {
            var nI = ++this.i;
            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();

See test/chronoman.js for additional examples.

API

See docs.

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].