New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ml-game-loop

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ml-game-loop

Simple game loop

  • 0.5.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-87.5%
Maintainers
1
Weekly downloads
 
Created
Source

game-server-loop

Simple game loop that allow queue of sync instructions.

Installation

npm install ml-game-loop --save

Usage

'use strict';

var GameLoop = require('ml-game-loop');

var loop = new GameLoop(),
    i = 0;

// this will run every time loop is started
// every time will have counter instead writing new line
loop.add(function (time, diff) {
    // time is current timestamp with milliseconds
    // diff is a time that passed since last execution
    process.stdout.write("\r every time!" + String(i++));
});

// this will run every after at least 100ms pass but always after previous callback
loop.throttle(100, function (time, diff) {
    process.stdout.write("\n* EVERY 100 MS !!!!!! *\n");
});

// as above but after 1000ms and it is named "every-second"
loop.throttle(1000, function (time, diff) {
    process.stdout.write("\n*** ALWAYS AFTER 1 SECOND - 1000 MS !!!!!! ***\n");
}, 'every-second');

/*
 * start loop, remember that callback always run in same order so if all three callbacks are valid (and all are on first start)
 * you will see three sentences
 * - every time! X
 * - * EVERY 100 MS !!!!!! *
 * - *** ALWAYS AFTER 1 SECOND - 1000 MS !!!!!! ***
 * ALWAYS in same order
 */
loop.start();

setTimeout(function () {
    // this will pause the loop after 5 seconds
    loop.pause();
    // this will stop execution of "every-second" callback, use loop.enable('every-second') to resume it
    loop.disable('every-second');
}, 5000);

setTimeout(function () {
    // this will pause the loop after 7 seconds, 2 seconds after pause
    loop.resume();
}, 7000);

setTimeout(function () {
    // this will stop the program after 10 seconds of working
    loop.stop();
}, 10000);

Have fun!

Keywords

FAQs

Package last updated on 04 Sep 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc