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

guvner

v1.0.0

Published

Provides the ability to run long-lasting computations without hogging the single thread

Downloads

4

Readme

Guv'ner

Guv'ner is a way to make a long-running process execute without blocking JavaScript's single thread.

About

JavaScript has only one thread, and is thus not optimized for long-running computations. Usually developers put their long-running functions into a window.requestAnimationFrame or setTimeout to free up the UI in browsers or the server code in a Node backend. However, it is difficult to determine the correct amount of work to do in each function call, as machines vary wildly on processing power.

Guv'ner introduces the ability to self-regulate the amount of work done by this long-running function, much like a Centrifugal Governor on an engine. When given a function with takes in a specified number of "work steps" to execute, Guv'ner will adjust the number of work steps executed to stay within the time parameter specified by the caller. This adjustment is made anew each execution, keeping the time of execution as close as possible to the desired amount.

Specification

guvner(fn[, duration]) -> Promise

The exported guvner function takes in a function to execute and an optional duration in milliseconds. The function must take in a single number parameter which correlates linearly with how much work the function will do before it exits.

The function must return a truthy value when it is finished with it's work, which will tell the guvner function to stop running and resolve the promise. This truthy value will be the resolved value of the promise which is returned from calling guvner.

The function provided to guvner should use closure to keep track of it's state.

Example

var guvner = require('guvner');

var num = 0;
var count = function(steps){
  for (var i = 0; i < steps; i++){
    num++;
    if (num >= 10000){
      return num;
    }
  }
};
guvner(count, 30)
.then(function(result){
  console.log(result);
});