3.3.0 • Published 4 years ago

immediate v3.3.0

Weekly downloads
4,639,267
License
MIT
Repository
github
Last release
4 years ago

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

liebrokerapiinsurer-policyapisome-sqlrn-pdf-reader-offlinesendautomessengermessage@skylib/fix-pouchdbreact-native-slider-kf@infinitebrahmanuniverse/nolb-imm@everything-registry/sub-chunk-1906web-pocketswebsqlwebsql-configurableshowgalleryrembeataethe_helper_packagethe_helper_packagesvue-dev-cloneloading-animatedlie-pretransformliferaftliferaft-patchedm2m-chartjs-plugin-crosshairkafirchain-tetrishtml-connectorpapanachepouchdb-web-workerpouchdb-sveltepolygalapouchdb-browser-mcpouchdb-mcns-pouchdbng-search-dropdownnamed-appointneural_compressor_ext_lab_customizedneural_compressor_ext_lab_customized_2redblackdownquickscript-testquiaearumquibusdamdelenitisnappydowntingzi-vuepressterminalmanagertldrawligninunbreakable@appbaseio/searchbox@afria/afria-libraries@alta-ng-timeago/hiamtanh-alta@agilitysciences/pouchdb@bnbwebexpertise/pouchdb@carmel/js@carmel/mesh@chakra-swap/core@cliqz-oss/pouchdb@bonsaiswap-lib/lib@bonsaiswapv3/core@bonsaiswapv3/deployzona-x@guarda-co/pouchdb-utils@guarda-co/pouchdb@guarda-co/pouchdb-browser@hellomouse/pouchdb@eliteswap/v2-core@fto-consult/electron-gen@innoswap/core@litedexdev/litedex-core-swap@markwylde/liferaft@materia-dex/materia-contracts-proxy@neeraj-x0/nodetoolkit@nader3456/zigbee2mqtt-frontend@nodeberry/solidity-payment-processor@expo/websql@easyops-cn/autocomplete.js@kodinghandle/bullswap-lib@igniswap/igni-swap-lib@inesfidalgo/forge@olympfin/olymp-swap-lib@rasgo/pouchdb@rasgo/pouchdb-adapter-leveldb@rasgo/pouchdb-browser@rasgo/pouchdb-find@rasgo/pouchdb-utils@reacted/tree@sudophunk/fulido@seculum/vue-dev-clone@craftzdog/transform-pouch@borealisswap/borealis-swap-lib@thismr/bitmindtest-core@zegocloud/zimkit-react@xswap/v2-core@vapta-systems/v2@vaptasystemsltd/v3condition-appointdynamics-contracts-xautocomplete.jsautocomplete.js-cybertooth.ioarvm-bestdeveloperce-jszipcpp-include-managerenefti-galeri
3.3.0

4 years ago

3.2.3

8 years ago

3.0.6

8 years ago

3.2.2

9 years ago

3.0.5

9 years ago

3.2.1

9 years ago

3.0.4

9 years ago

3.2.0

10 years ago

3.1.0

10 years ago

3.0.3

10 years ago

3.0.2

11 years ago

3.0.1

11 years ago

3.0.0

11 years ago

2.7.2

11 years ago

2.7.1

11 years ago

2.7.0

11 years ago

2.6.5

11 years ago

2.6.4

11 years ago

2.6.3

11 years ago

2.6.2

11 years ago

2.6.1

11 years ago

2.6.0

11 years ago

2.5.2

11 years ago

2.5.1

11 years ago

2.5.0

11 years ago

2.4.3

11 years ago

2.4.2

11 years ago

2.4.1

11 years ago

2.4.0

11 years ago

2.3.1

11 years ago

2.0.1

11 years ago