Skip to content

Instantly share code, notes, and snippets.

Avatar

Yassine Elouafi yelouafi

View GitHub Profile
@threepointone
threepointone / gen-ric.js
Created Dec 23, 2016
generators + requestIdleCallback
View gen-ric.js
// this is a generic runner for iterators
// for every yield, it checks to see if any time is remaining
// on the idle loop, and executes more work if so.
// else, it queues up for the next idle period
function go(it, callback){
requestIdleCallback(deadline => {
let val = it.next()
while(!val.done){
if(deadline.timeRemaining() <= 0){