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

game-loop-dispatch

v0.1.0

Published

A low level game loop that emits events

Downloads

16

Readme

Game Loop Dispatch

A low level game-loop for nodejs that provides the basic events. Game Loop Dispatch is small maybe 40 lines of code and just extends node's built-in EventEmitter. Being able to modify/extend the event hooks one can customize the loop for their game.

Install

Use npm

npm install game-loop-dispatch

Usage

The below code samples are included in the examples folder and can be run with the following

node examples/basic.js
node examples/advanced.js

Basic Usage

To start with just include and instantiate the game loop

var GameLoopDispatch = require('game-loop-dispatch');

var gameLoop = new GameLoopDispatch({
    // only require value is the interval in milliseconds
    'interval':1000
});

gameLoop.tick = function(){
    console.log('tick');
};

gameLoop.start();

You should see in a stdout every second

tick
tick
tick

Advanced Usage

Advanced usage showing how you can add an additional event hooks to extend the loop functionality. In this example we will add tickStart and tickEnd so that we can pause/start the gameloop while it is processing async calls. Otherwise the loop would continue to fire every 1 sec and things would get out of control.

var GameLoopDispatch = require('game-loop-dispatch');

var gameLoop = new GameLoopDispatch({
    // only require value is the interval in milliseconds
    'interval':1000
});

gameLoop.tick = function(){
    // hack to rescope this because of setTimeout 
    //var self = this; 

    // GameLoopDispatch extends eventEmitter so `emit` is
    // provided internally.  In this example a `tickStart`
    // event is emited at the start of every `tick` event
    this.emit('tickStart');
    
    // our standard tick marker
    console.log('tick');

    // imagine this was some async call to a processingQueue
    // for AI Entities or Player Movements that takes 4 seconds
    // to process
    setTimeout(function(){
        // now that everything was process broadcast
        // an event for tickEnd
        // note we use gameLoop because `this` is wrong context
        gameLoop.emit('tickEnd');
    }, 4000);
            
};

//
// Create Listeners for our new Event hooks
//
gameLoop.on('tickStart', function(){
    console.log('top of tick phase');
    // lets pause the loop while we process
    gameLoop.pause();

});

gameLoop.on('tickEnd', function(){
    console.log('end of tick phase');
    // now that tick is complete lets restart the loop
    gameLoop.start();
});

gameLoop.start();

Todo / Contributions

This is an initial release as I'm prototyping a game. Some additional low-level events are still needed such as some 'loader' event system for static content and or other async behavior. Open to suggestions and ideally would like to build this like lodash where one can generate the game-loop function hooks they need.