Geek Logger
Javascript + Structured Concurrency

stratifiedjs is an interesting approach to introduce concurrency programming to javascript,
first I learned about it in infoQ

It adds a small number of new constructs (waitfor/and, waitfor/or, waitfor()/resume, hold, spawn, using), and it extends the semantics of the constructs of the base JS language (i.e. sequencing, looping, conditionals, exceptions, etc) to work naturally with concurrent code paths. 

the code is pure javascript except for those new semantics like this:

var result;
waitfor {
  result = performGoogleQuery(query);
}
or {
  result = performYahooQuery(query);
}

it executes both functions simultaneously and then waits for them to be completed and upon completion of one, it automatically terminates the other.

you can read/view a quick and well organized demo in their website, they demonstrated it in OSCON2010.

the interesting part is that it works both on client side and server side. in client side all you have to do is to inlcude a small 20k file, called oni Apollo. and in server side they’re poring Apollo to Node.js.



Blog comments powered by Disqus