Skip to content

Instantly share code, notes, and snippets.

@narqo
Last active October 21, 2015 21:00
Show Gist options
  • Save narqo/ec0b9294588f68e9f79e to your computer and use it in GitHub Desktop.
Save narqo/ec0b9294588f68e9f79e to your computer and use it in GitHub Desktop.
/**
* `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