node package manager

actor

actor

Experimental library implementing Scala like Actors in javascript. Library uses [generators] introduced in JavaScript 1.7 to provide continuation passing mechanism with a linear control flow but asynchronous nature. Idea is to use implement actors in following fashion:

var actor = Actor(function act() {
  // yield saves continuation untill returned promise is resolved
  var data = yield getDataAsync()
  doSomething(data)
})

Actor will use yield to save continuation until promise returned by getDataAsync asynchronous function is fulfilled. After generator will be resumed with a fulfill value, so that it gets assigned to data variable. As a result program is executed sequentially without blocking event-loop.

This library has been tested on Firefox using teleport and on Jetpack. It's very likely that this library will work / won't be to hard to make it work on rhino based platforms like RingoJS.

Examples

Install

npm install actor

Play

teleport activate
open http://localhost:4747/packages/actor/

Prior Art / Source of inspiration