npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chronoman

v1.3.1

Published

Utility class to simplify use of timers created by setTimeout

Downloads

51

Readme

chronoman

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();

NPM version Build Status Built with Grunt

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 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.