Skip to content

Instantly share code, notes, and snippets.

@yorkie
Created August 13, 2014 07:53
Show Gist options
  • Save yorkie/3ff4bd971db5857ce6da to your computer and use it in GitHub Desktop.
Save yorkie/3ff4bd971db5857ce6da to your computer and use it in GitHub Desktop.
idle-hands is not really idle
var request = require('request');
var idlehands = require('idle-hands');
var timerCount = 0;
var idleCount = 0;
function repeat(cb) {
setImmediate(function() {
timerCount += 1;
});
idlehands.once('idle', function() {
idleCount += 1;
console.log(timerCount, idleCount);
cb(cb);
});
}
idlehands.once('idle', function(){
repeat(repeat);
});
idlehands.start();
setInterval(function(){
request('http://google.com');
}, 1000);
@yorkie
Copy link
Author

yorkie commented Aug 13, 2014

The output:

1 1
2 2
....
....
66377 66377
66378 66378
66379 66379
66380 66380
66381 66381
66382 66382
66383 66383
66384 66384
66385 66385
66386 66386
66387 66387
66388 66388
66389 66389

Such that the event idle will be called in every tick, it just run 3:run_idle function like this digram: http://readtrend.com/icon/5311

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment