GitHub - jamiebuilds/tickedoff: Tiny library (<200B gzip) for deferring somet...

 5 years ago
source link: https://github.com/jamiebuilds/tickedoff
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.



Tiny library (<200B gzip) for deferring something by a "tick"

  • Using setTimeout is actually a bit slow because its clamped to 4ms
  • setImmediate is not available in most places (and probably never will be)
  • process.nextTick is only in Node
  • Promise#then needs polyfills in places
  • tickedoff uses 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


yarn add tickedoff


const defer = require('tickedoff');

defer(() => console.log(3));
// 1
// 2
// 3


$ node perf.js
process.nextTick x 10000 = 24ms
Promise#then x 10000 = 29ms
setImmediate x 10000 = 68ms
setTimeout x 10000 = 13506ms

About Joyk

Aggregate valuable and interesting links.
Joyk means Joy of geeK