Created
November 29, 2020 15:22
-
-
Save 911992/5b34d3a16a5acfe380f2054f8910a0be to your computer and use it in GitHub Desktop.
JS simulated-thread using async func(no synchronization)
This file contains 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> | |
<!-- | |
https://github.com/911992 | |
--> | |
<html> | |
<head> | |
<script type="text/javascript"> | |
function rand_css_col(){ | |
var col = Math.random()*0xffffff; | |
return "#"+(("000000"+(col).toString(16)).substr(-6)); | |
} | |
async function async_test(){ | |
var _elem = document.getElementById("a"); | |
for(var a=0;a<11;a++){ | |
setTimeout(function(){ | |
_elem.style.backgroundColor = rand_css_col(); | |
},a*1000); | |
} | |
} | |
</script> | |
<title>TODO supply a title</title> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
</head> | |
<body> | |
<div id="a">TODO write content | |
<div> | |
<button onclick="async_test()"><code>async</code> js func Go bro</button> | |
</div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment