periodical-executer

    0.1.2 • Public • Published

    periodical-executer(object)

    Build Status Coverage Status

    This is a port of the PrototypeJS class PeriodicalExecuter. It addresses the common need of calling a particular function periodically, as required by all sorts of "polling" mechanisms (e.g., a chatroom or mail client).

    PeriodicalExecuter accepts an object with three properties: one for a callback function (which is passed the this parameter), another for a frequency number (defaults to 2000 milliseconds), and one for a decay number (defaults to 1000 milliseconds). The class then exposes two instance methods called start and stop, which does as their names implies.

    Installation

    npm install periodical-executer

    Usage

    var PeriodicalExecuter = require('periodical-executer');
    
    var PE = new PeriodicalExecuter({
        callback: function(pe) {
            if (!confirm('Want me to annoy you again later?')) {
                pe.stop();
            }
        },
        frequency: 3000,
        decay: 2000
    });
    
    PE.start();
    

    In the example above, PeriodicalExecuter shields you from multiple parallel executions of a callback function, should it take longer than the given interval to execute. This is especially useful if you use one to interact with the user at given intervals (e.g. use a prompt or confirm call): this will avoid multiple message boxes all waiting to be actioned.

    Tests

    npm test

    Contributing

    In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code. See the CONTRIBUTING file for more detailed information.

    Install

    npm i periodical-executer

    DownloadsWeekly Downloads

    5

    Version

    0.1.2

    License

    MIT

    Unpacked Size

    8.19 kB

    Total Files

    7

    Last publish

    Collaborators

    • ramumb