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

set-asap

v1.0.0

Published

setAsap - async variable call control

Downloads

4

Readme

set-asap

async variable call control

A replacement for your setImmediate calls.

Installation

npm install --save set-asap

API

setAsap( fn: function [, maxTime: number[, minTime: number ]]) => id: number

  • fn - function you want to execute
  • maxTime - the maximum time you need it to be executed. ( Defaults to: 500 )
  • minTime - the minimum time you need it to be executed. ( Defaults to: 0 )

clearAsap( id ) => bool

  • id - id returned by setAsap

Usage example

es6

import { setAsap, clearAsap } from 'set-asap'

function doSomethingHeavy () {
  for ( var i = 0; i < 3000000; i++ ) {}
}

for ( var i = 0; i < 300; i++ ) {
  setAsap( doSomethingHeavy )
}

es5

var setAsap = require( 'set-asap' )
var clearAsap = setAsap.clearAsap

function doSomethingHeavy () {
  for ( var i = 0; i < 3000000; i++ ) {}
}

for ( var i = 0; i < 300; i++ ) {
  setAsap( doSomethingHeavy )
}

FAQ

What is this?

This module provides a timer method for running variable async calls.

What is a timer method?

Timer async methods are the API methods which interact with the next ticking stack. Examples:

  • setImmediate
  • setTimeout
  • setInterval

Why did you bring this up?

Javascript doesn't always have great performance on all engines, thats a fact, specially on browsers where they have to update the UI on the same JS process.

Besides, Javascript is meant to be non-blocking IO driven but if you fill up the next tick stack it will act as IO blocking.

Wait, why does that happen?

Under the hood, timer async methods just place up the function provided by the developer at the end of an array.

When the engine has nothing to do, it just picks up the first one that is eligible to run and starts its execution, if that execution or more of them calls up more, you will end up filling the next stack, resulting in a blocking IO.

And whats bad on filling up the next stack?

On Node.JS

If you fill up your next tick stack and it is serving an HTTP service, the server will take longer to start handling new requests, because it uses the that stack.

Browser

Browsers use Javascript to handle UI redrawing, which means that if you block the engine, the UI will crash while handling all the ticking calls you got on.

Can you give me an example on how to block the engine?

sync

while ( 1 ) {}

async

(function runMySelf () {
  setInterval( runMySelf, 4 )
})()

How does this fixes this issue?

You won't block the IO, you don't want to, but it could happen whenever your code has lot of things to handle, this method is a mixture between the setImmediate and setInterval, but instead of a fixed timing, it places your call in a dynamic window without respecting priority.

This method allows the engine to handle other resources on the spare time.

Could you please represent it on a graphical way?

If you meant terminal graphicall way, yes.

Legend:

  • - - spare time
  • [number] - execution
  • [char] - each character means a tick

Imagine a case where I want to fill 8 executions on the next second:

Case with setImmediate

12345678----------------------

Case with setAsap

---71--4--5-----9-6---2--3--8-