Skip to content

Instantly share code, notes, and snippets.

View yelouafi's full-sized avatar

Yassine Elouafi yelouafi

View GitHub Profile
@threepointone
threepointone / gen-ric.js
Created December 23, 2016 04:59
generators + requestIdleCallback
// 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){