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

immediate

v3.3.0

Published

A cross browser microtask library

Downloads

41,264,624

Readme

immediate Build Status

testling status

npm install immediate --save

then

var immediate = require("immediate");

immediate(function () {
  // this will run soon
});

immediate(function (arg1, arg2) {
  // get your args like in iojs
}, thing1, thing2);

Introduction

immediate is a microtask library, descended from NobleJS's setImmediate, but including ideas from Cujo's When and RSVP.

immediate takes the tricks from setImmediate and RSVP and combines them with the scheduler inspired (vaguely) by when's.

Note versions 2.6.5 and earlier were strictly speaking a 'macrotask' library not a microtask one, see this for the difference, if you need a macrotask library, I got you covered.

Several new features were added in versions 3.1.0 and 3.2.0 to maintain parity with process.nextTick, but the 3.0.x series is still being kept up to date if you just need the small barebones version

The Tricks

process.nextTick

Note that we check for actual Node.js environments, not emulated ones like those produced by browserify or similar.

queueMicrotask

Function available in major browser these days which you can use to add a function into the microtask queue managed by V8.

MutationObserver

This is what RSVP uses, it's very fast, details on MDN.

MessageChannel

Unfortunately, postMessage has completely different semantics inside web workers, and so cannot be used there. So we turn to MessageChannel, which has worse browser support, but does work inside a web worker.

<script> onreadystatechange

For our last trick, we pull something out to make things fast in Internet Explorer versions 6 through 8: namely, creating a <script> element and firing our calls in its onreadystatechange event. This does execute in a future turn of the event loop, and is also faster than setTimeout(…, 0), so hey, why not?

Tricks we don't use

setImmediate

We avoid using setImmediate because node's process.nextTick is better suited to our needs. Additionally, Internet Explorer 10's implementation of setImmediate is broken.

Reference and Reading