Created
May 3, 2018 01:56
-
-
Save zootella/00d70504f296301288dac86c00024c60 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>spin5</title> | |
<script src="http://code.jquery.com/jquery-3.3.1.min.js"></script> | |
<script src="http://cdn.jsdelivr.net/bluebird/3.5.0/bluebird.min.js"></script> | |
</head> | |
<body> | |
<p>It's <span id="my-clock"></span> milliseconds since January 1970</p> | |
<script> | |
setInterval(function() { | |
var d = new Date(); | |
$("#my-clock").text(d + ", " + d.getTime()); | |
}, 100); | |
</script> | |
<p><input id="my-button" type="button" value="Spin"/></p> | |
<p>using bluebird, spin5 counted to: <span id="my-result"></span><p> | |
<script> | |
var count, start; | |
$("#my-button").click(function() { | |
count = 0; | |
start = Date.now(); | |
again(); | |
}); | |
function again() { | |
count++; | |
if (Date.now() < start + 2000) Promise.resolve().then(again); | |
else $("#my-result").text(count); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment