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 🙏

© 2026 – Pkg Stats / Ryan Hefner

repeat-runner

v1.1.3

Published

A javascript tool for run repeat code.

Downloads

40

Readme

repeat-runner

Build Status Coverage Status NPM Download NPM Version NPM License

A javascript tool for run repeat code.

📌 Here is 1.x version, want 0.x doc? click me.

Installing

$ npm install repeat-runner
// or
$ npm install repeat-runner --save

Example

Repeat sync code.

import RepeatRunner from 'repeat-runner';

const repeatHello = new RepeatRunner( () => console.log('hello'), 1000);

// start and stop it 3 seconds later, 
// it's equivalent to:
// repeatHello.start();
// repeatHello.stop(1000 * 3);
repeatHello.start().stop(1000 * 3);

// result: print 'hello' every second util stop 
/*
hello
hello
hello
*/

Repeat async code.
If your code contain async process, and you hope set next repeat after async process complete. Just make the function return a Promise. Of course, you can use async/await grammar.
Notice: Set third parameter to true (see API), will make runner stop when Promise#reject or any uncatched error .

// simple-1
// use Promise only
const repeatAsyncHello = new RepeatRunner( () => {
    return new Promise( (resolve, reject) => {
        setTimeout( () => {
            console.log('async hello');
            resolve();
        }, Math.random() * 5000);
    });
}, 1000);



// simple-2
// with async/await grammar
async function fetchUsers () {
    const userList = await fetch('/users');
    updateUserTable(userList);
}

const autoUpdateUsers = new RepeatRunner(fetchUsers, 20000);

function updateUserTable (userList) {
    /* ... update UI */
}



// simple-3
// stop repeat via Promise#reject
let cnt = 0;

new RepeatRunner(counting, 1000, true).start();

function counting () {
    return new Promise( (resolve, reject) => {   
        // print         
        console.log(cnt);
        // plus
        cnt++;

        if (cnt > 4) {
            reject(); // stop it 
        } else { 
            resolve(); 
        }
    });
};

// result
/*
0  // 0s
1  // 1s
2  // 2s
3  // 3s
4  // 4s, and stop now
*/

API

Create instance

Syntax

new RepeatRunner(execFunction, interval)

Parameters

execFunction: {function} this function wrap the code that need repeat
interval: {number} repeat interval (unit: ms)
stopWhenError: {boolean} configure whether to allow stop repeat when error occur(default is false)

Instance property & methods

RepeatRunner.isRunning [read-only] get current status
RepeatRunner.interval [read/write] get current interval or set new interval
RepeatRunner.execFunc [read/write] get current execFunction or set new execFunction
RepeatRunner.lastError [read-only] get last error that occur in execFunction
RepeatRunner.prototype.start(delay = -1) [return this] start runner
RepeatRunner.prototype.stop(delay = -1) [return this] stop runner

Dependencies

repeat-runner depends on a native ES6 Promise and WeakMap implementation to be supported.
If your environment doesn't support ES6 Promises, you can polyfill (Promise, Weakmap).

License

MIT