Overview
Strands adds coroutine and cooperative threading support to the JavaScript language that enables blocking capabilities for asynchronous event callbacks. This makes asynchronous code refreshingly readable and comprehensible.
With Strands fetching a document using XmlHttp goes from looking like this:
function handleResponse(responseText) {
document.getElementById("myElem").innerHTML = responseText;
}
strands.request("http://www.url.com/", handleResponse);
to this:
document.getElementById("myElem").innerHTML = strands.request("http://www.url.com/");
And an animation sequence goes from looking like this:
var left = 0;
function onTimer() {
left += 10;
if (left <= 300) {
document.getElementById("myElem").style.left = left;
setTimeout(onTimer, 30);
}
}
onTimer();
to this:
for (var left = 0; left <= 300; left += 10) {
left += 10;
document.getElementById("myElem").style.left = left;
sleep(30);
}
Any operation that requires a callback function is a candidate for
blocking.
Keep in mind that blocking does not mean that the entire JavaScript runtime locks up waiting for an operation to finish. Instead, Strands makes use of co-operative multitasking. When you use the blocking operator, you are yielding control to the JavaScript runtime to execute other operations until your operation provides a return value.
More details about writing Strands can be found in the coding section of the documentation.