previous | top | next
Composing concurrency
- Concurrency constructs in SJS are compositional
- E.g. here we use '@' on a fork-join expression:
function promptNumber(name) {
try {
... create div with text input & button elements
... append to body
Ajax.DOM.waitForEvent("click", button);
return text_input.value;
}
finally {
output.removeChild(div);
}
}
function clearAll() {
Ajax.DOM.waitForEvent("click", "clearall");
output.innerHTML = "";
}
while (true) {
calculate(promptNumber("1."), promptNumber("2.")) @
Ajax.DOM.waitForEvent("click", "restart") @
clearAll();
}
High-level concurrency for JS - http://www.croczilla.com/stratified