JavaScript Strands adds coroutine and cooperative threading support to the JavaScript language to enable blocking capabilities for asynchronous event callbacks. This makes code that utilizes asynchronous operation much more linear, readable, and manageable. Strands is built upon Narrative JavaScript written by Neil Mix, and much of Narrative JavaScript has remained in Strands including much of this documentation. Download Strands here.
Why?
In JavaScript your code can't simply wait until an event has fired -- the event must always be handled by a separate, asynchronous event handler. Sometimes this is fine, but it often forces what ought to be a simple sequence of statements into gnarly contortions. It also breaks the ability to encapsulate functionality because calling functions must know to provide a callback handler. Strands provides the ability to suspend and resume threads of execution. Execution can suspend resume when the event is finished. This allows you to write hard-to-read asynchronous event handling in simple, linear, readable code that encapsulates implementation.
How it Works
Strands consists of a compiler and a runtime library. You write normal JavaScript and use the provided API to pause execution for asynchronous events, and the compiler will parse and translate the code into normal (asynchronous) JavaScript. You then deploy the compiled code along with a runtime library. You can also use native JavaScript 1.7 features to run Strands natively (no compilation, just the runtime library) JS 1.7 environments like Firefox 2+ and Rhino 1.7.
Since generated code is often difficult to read, great care is taken to make Strands as debugging friendly as possible: line numbering of the source code is kept intact in the compiled code, stack ordering is preserved, original source can be included in the output, and exception support does not result in unnecessary catching and re-throwing of exceptions.
The Strands project is based on Narrative JavaScript which uses the parser written by Brendan Eich narcissus, a JavaScript parser written in JavaScript for the Mozilla project. The Strands logo was created by David Bryan.
Project Status
Strands is currently in Beta. Strands is released under the MPL license.