1.0.2 • Published 8 years ago
tickedoff v1.0.2
tickedoff
Tiny library (<200B gzip) for deferring something by a "tick"
- Using
setTimeoutis actually a bit slow because its clamped to 4ms setImmediateis not available in most places (and probably never will be)process.nextTickis only in NodePromise#thenneeds polyfills in placestickedoffuses whatever the best available option is- There are more robust libraries/polyfills but they are larger in size
- This is all especially good for libraries to use
Install
yarn add tickedoffUsage
const defer = require('tickedoff');
console.log(1);
defer(() => console.log(3));
console.log(2);
// 1
// 2
// 3Perf
$ node perf.js
process.nextTick x 10000 = 24ms
Promise#then x 10000 = 29ms
setImmediate x 10000 = 68ms
setTimeout x 10000 = 13506ms