Skip to content

Instantly share code, notes, and snippets.

@911992
Created November 29, 2020 15:22
Show Gist options
  • Save 911992/5b34d3a16a5acfe380f2054f8910a0be to your computer and use it in GitHub Desktop.
Save 911992/5b34d3a16a5acfe380f2054f8910a0be to your computer and use it in GitHub Desktop.
JS simulated-thread using async func(no synchronization)
<!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