Skip to content

Instantly share code, notes, and snippets.

@etki
Created February 20, 2017 10:15
Show Gist options
  • Save etki/649cb2b43a6b0ed588e183cb98190388 to your computer and use it in GitHub Desktop.
Save etki/649cb2b43a6b0ed588e183cb98190388 to your computer and use it in GitHub Desktop.
var start = new Date().getTime(),
checkpoint = null,
delay = 1000,
end = start + (delay * 2),
current;
setTimeout(function () {
if ((current = new Date().getTime()) < end) {
console.log('we\'re borked');
} else {
console.log('setTimeout has been delayed as expected');
}
}, delay);
while ((current = new Date().getTime()) < end) {
if (!checkpoint || (checkpoint + 200 < current)) {
console.log((current - start) + ' ms have passed');
checkpoint = current;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment