previous | top | next
Spawing 'threads' from event handlers
- SJS functions can freely be called from 'normal' JS, including event handlers
- When called this way, an SJS function is automatically spawned to the background
function animation() {
var elem = document.createElement("div");
elem.setAttribute("style",
"position:relative; width:20px; height:20px;background-color:red;");
document.getElementById("playpen").appendChild(elem);
for (var x=0; x<400; x+= 5) {
elem.style.left = x;
hold(10);
}
elem.parentNode.removeChild(elem);
}
In <body>:
<button onclick="animation();">Spawn animation</button>
High-level concurrency for JS - http://www.croczilla.com/stratified