Last active
October 21, 2015 21:00
-
-
Save narqo/ec0b9294588f68e9f79e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* `window.requestAnimationFrame` rewritten in `Promise`s way. | |
* See https://api.dartlang.org/1.12.2/dart-html/Window/animationFrame.html | |
*/ | |
const animationFrame = () => new Promise(resolve => window.requestAnimationFrame(resolve)); | |
function test(prefix, fn) { | |
var counter = 0; | |
const next = function() { | |
if (counter++ < 10) { | |
//console.log(prefix + ': did step ' + counter); | |
return fn(next); | |
} | |
}; | |
return next(); | |
} | |
test('PROMISE', function(step) { | |
animationFrame().then(function(t) { | |
console.log('promise' + t); | |
step(); | |
}); | |
}); | |
test('REQUEST', function(step) { | |
requestAnimationFrame(function(t) { | |
console.log('request' + t); | |
step(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment