Skip to content

Instantly share code, notes, and snippets.

@Quramy
Created September 3, 2015 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Quramy/1b1f987512763e6486ba to your computer and use it in GitHub Desktop.
Save Quramy/1b1f987512763e6486ba to your computer and use it in GitHub Desktop.
request idle callback sample
'use strict';
var counter = (next, loopNum, wait) => {
var count = 0;
var last = Date.now();
var logger = () => {
wait && heavyFunction(wait);
console.log(next.name, Date.now() - last , count);
count++;
last = Date.now();
if(count < loopNum) {
next(logger);
}
};
next(logger);
};
// 何か重たい処理
var heavyFunction = (wait) => {
var start = Date.now();
for(;;) {
if(Date.now() - start > wait) {
return;
}
}
};
counter(requestAnimationFrame, 15, 60);
counter(requestIdleCallback, 15, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment