The Ashes

Technology, Science and other news
September 4, 2009

Stratified JavaScript; Concurrency features in JavaScript

Posted by : admin
Filed under : General

Alex Fritze has introduced Stratified JavaScript, an experiment that allows us to play with some concurrency features in JavaScript in a cross browser way.

It features:

The ability to pause execution: hold()

JAVASCRIPT:

  1.  
  2.  var elem = document.getElementById(“animated_element”);
  3.   var x = 0;
  4.   while (true) {
  5.     elem.style.left = x;
  6.     x = (x + 10) % 200;
  7.     hold(100);
  8.   }
  9.  

Fork-Join Parallelism

JAVASCRIPT:

  1.  
  2.  function animate(elemname, duration_ms, step_ms) {
  3.     var elem = document.getElementById(elemname);
  4.     var start_time = new Date();
  5.     var x = 0;
  6.     do {
  7.       elem.style.left = x;
  8.       x = (x + 10) % 200;
  9.       hold(step_ms);
  10.     } while (duration_ms> new Date() – start_time);
  11.   }
  12.  
  13.   function par(a, b) {
  14.     alert(“all done”);
  15.   }
  16.  
  17.   par(animate(“animated_element_1”, 10000, 100),
  18.       animate(“animated_element_2”, 7000, 80));
  19.  

Exploratory parallelism

JAVASCRIPT:

  1.  
  2. animate(“animated_element_1”, 10000, 100) @
  3. animate(“animated_element_2”, 7000, 80);
  4.  
  5. alert(“all done”);
  6.  

Suspend/Resume

JAVASCRIPT:

  1.  
  2. function waitForEvent(event, elem) {
  3.     suspend {
  4.       var rv;
  5.       var listener_func = function(e) {
  6.         rv = e;
  7.         resume();
  8.       };
  9.       elem.addEventListener(event, listener_func, false);
  10.     }
  11.     finally {
  12.       elem.removeEventListener(event, listener_func, false);
  13.     }
  14.     return rv;
  15. }
  16.  

Under the hood, Stratified JavaScript is executed by a runtime based on Oni.

Kris Zyp asked for a comparison to Narrative JavaScript or JavaScript strands and Alex came back with:

The most important enhancement of SJS versus Narrative JavaScript or Strands is the support for ‘exploratory parallelism’ or ‘parallel selection’, as embodied by SJS’s Alt operator (‘@’). There are many problems that are tricky to express with just threads, but which can be expressed elegantly in a structured, compositional way with the use of Alt.

Tags :

No Comments

(required)
(will not be published) (required)
(opitional)

cciash.com EN ES IT DE PT CZ FR RU
August 2017
M T W T F S S
« Sep    
 123456
78910111213
14151617181920
21222324252627
28293031  

Pages

Categories

Resources

There are many online poker site where you can play but at poker.hk you can play the poker games with all the knowledge you need related to the game with the poker school available in both the English and Chinese language.

Super Casino

Now you can bet on any sports and any sporting events from all the comfort from your home. Bet770 allows you to bet on any events and match with in just 3 clicks. They also offers great odds on football betting for every premier and champions league match. Get £50 free in bets when you register.

Bingo770, offering best online bingo games with £7.70 free no deposit Bonus!