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

@gibme/timer

v22.0.0

Published

A simple timer/metronome

Downloads

624

Readme

Event-based Timer/Metronome

A simple, event-driven timer library for Node.js built on EventEmitter. Provides a base Timer for interval-based ticks, plus SyncTimer and AsyncTimer helpers that execute functions on each tick and emit typed results.

Documentation

https://gibme-npm.github.io/timer/

Installation

npm install @gibme/timer

or

yarn add @gibme/timer

Usage

Basic Timer

import Timer from '@gibme/timer';

const timer = new Timer(60_000);

timer.on('tick', () => {
    // runs every 60 seconds
});

timer.start();

Auto-Start with Arguments

const timer = new Timer(5_000, true, 'hello', 42);

timer.on('tick', (greeting: string, value: number) => {
    console.log(greeting, value); // "hello" 42
});

SyncTimer

Wraps a synchronous function, executing it on each interval and emitting the result via the data event.

import { SyncTimer } from '@gibme/timer';

const timer = new SyncTimer(() => Math.random(), 1_000, true);

timer.on('data', (value, timestamp, interval) => {
    console.log(`Got ${value} at ${timestamp}s (every ${interval}ms)`);
});

AsyncTimer

Wraps an asynchronous function, awaiting it on each interval and emitting the resolved value.

import { AsyncTimer } from '@gibme/timer';

const timer = new AsyncTimer(async () => {
    const res = await fetch('https://api.example.com/data');
    return res.json();
}, 30_000, true);

timer.on('data', (payload, timestamp, interval) => {
    console.log(payload);
});

timer.on('error', (error) => {
    console.error('Request failed:', error);
});

sleep

A simple async sleep utility.

import { sleep } from '@gibme/timer';

await sleep(2_000); // wait 2 seconds

API

Timer

new Timer(interval: number, autoStart?: boolean, ...args: any[])

| Parameter | Type | Default | Description | |-----------|------|---------|-------------| | interval | number | | Milliseconds between ticks | | autoStart | boolean | false | Start immediately on construction | | ...args | any[] | | Arguments forwarded to every tick event |

Properties

| Property | Type | Description | |----------|------|-------------| | interval | number | The tick interval in milliseconds | | paused | boolean | Whether the timer is paused | | destroyed | boolean | Whether the timer has been destroyed |

Methods

| Method | Returns | Description | |--------|---------|-------------| | start() | void | Start the timer | | stop() | void | Stop the timer | | toggle() | boolean | Toggle on/off; returns true if now running | | tick(...args) | void | Force an immediate tick with optional arguments | | destroy() | void | Permanently stop and clean up the timer |

Events

| Event | Listener Signature | Description | |-------|--------------------|-------------| | tick | (...args: any[]) => void | Emitted on each interval tick | | start | () => void | Emitted when the timer starts | | stop | () => void | Emitted when the timer stops | | error | (error: Error) => void | Emitted on errors |

SyncTimer<Type>

Extends Timer. Executes a synchronous function on each tick.

new SyncTimer(func: () => Type, interval: number, autoStart?: boolean)

Emits a data event after each execution:

timer.on('data', (result: Type, timestamp: number, interval: number) => void)

AsyncTimer<Type>

Extends Timer. Executes an asynchronous function on each tick.

new AsyncTimer(func: () => Promise<Type>, interval: number, autoStart?: boolean)

Emits a data event after each execution resolves:

timer.on('data', (result: Type, timestamp: number, interval: number) => void)

Errors thrown or rejected by the function are emitted as error events.

License

MIT