Er.js: Erlang-in-JavaScript
Alex Graveley has built Er.js, a library that “piggybacks on Neil Mix’s Thread.js which fakes threading in JavaScript 1.7 using coroutines and nested generator continuations. The goal is to replicate Erlang’s concurrent lockless process model and message-passing APIs in JavaScript.”
Alex also added initial concurrent Ajax support:
XmlHttpRequest, AJAX and JSON integrate nicely with the process and message-passing model, allowing processes to avoid asynchronous JavaScript and callbacks.
Instead, using message-passing and concurrency, Er.js makes network access transparent, without blocking other processes or interactivity:
JAVASCRIPT:
result = yield Er.Ajax.get(“http://beatniksf.com/erjs/index.html”); alert(“Fetched Content: “ + result.Text);Under the covers, this is accomplished using a concurrently spawned process (started via Er.Ajax.spawn), which handles XmlHttpRequest internals. The spawned process uses Er.send to tell our process about download progress and completion.
Er.Ajax.get and others (post, json, etc) are implemented by yielding execution until the final message from the spawned process is received, and then returning it to the caller:
JAVASCRIPT:
function myGet(url) { var pid = Er.Ajax.spawn(Er.pid(), url); yield Er.receive({ From: pid, Success: _, _:_ }, function(msg) { return msg; }); }
You can see the test page to watch it in action.
Read more on the source site
No comments yet.
feel free to leave a comment
Comment Guidelines: Basic XHTML is allowed (a href, strong, em, code). All line breaks and paragraphs are automatically generated. Off-topic or inappropriate comments will be edited or deleted. Email addresses will never be published. Keep it PG-13 people!
XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>
All fields marked with " * " are required.

