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 🙏

© 2024 – Pkg Stats / Ryan Hefner

halt

v2.2.0

Published

node.js addon used for safely teminating javascript execution

Downloads

34

Readme

Halt

Halt is a node addon that makes it possible for the user to stop the execution of a V8 instance without kill the current loop. Timeouts are managed by creating a parallel event loop who's sole objective is to manage the timer. When a program is bottlenecked by the CPU, you may want to kill this event and that is the reason why we throw a nice CPU bound Exception on timeout.

Installation

npm install halt

Compatibility

From node 0.12 - node 9 included iojs 3

Timer

When an engine is busy, a program needs more time to end but consumes the same amount of cpu ticks. In this case we would like to give more time to this program to end his execution while he doesn't consume too many cpu ticks. That's why the timer will be restarted until the maximum amount of cpu ticks is reached or the program ends his execution. This maximum is determined by the value send to halt.start/run() and the cpu ticks per millisecond which is configurable and has 1000 as default value.

Usage

You can either kill the javascript executing thread by

  • starting a timer on a function with halt.run()
  • manually calling start, protect and clear on the halt module
var halt = require('halt')
halt.ticksPerMsec = 1010;

function goFetchSomeMilk () { /* ... */; return milk; }

// In this case, max cpu ticks = 1000 * 60 * 10 * 1010;
// If max cpu ticks is reached, stop waiting

// Automatic managing
halt.run(goFetchSomeMilk, 1000 * 60 * 10)
 
// Manually managing
halt.start(1000 * 60 * 10);
halt.protect(goFetchSomeMilk);
halt.clear();

Exception

When execution is forcefully terminated using TerminateExecution(), a catchable exception is generated. In case you have sensible code and you want to recover the exception and catch it, you can use:

var halt = require('halt')

function goFetchSomeMilk () { /* ... */; return milk; }

try{
    halt.start(50);
    try{
        halt.protect(goFetchSomeMilk);
    }
    catch(){
        /* What ever you want */
    }
    halt.clear();
}

License

alt cc This work is licensed under a [Creative Commons Attribution 4.0 International License] (http://creativecommons.org/licenses/by/4.0/)