Default at 3 workers. (Most processors today on both desktop and mobile are quad-core, => 1 main thread + 3 workers). Spawn them immediately.
An actor is a single function. Prototype additions are not taken into account (not straightforward to serialise). It behaves like a function, but async: arguments you give to the actor are passed through unaltered (but they must comply with the serialisation restrictions).
There's two ways to signify completion and both are bubbled up as events:
return something; and this.done(something);. The something argument is
optional and can be multiple in the case of the this.done method. The
this.done() method can be called multiple times per actor, making it useful
for map-reduce operations. Both ways can be used simultaneously.
var Cartographist = new Dyno.Actor(function aCartographist(countriesToMap) {
var self = this;
var canDo = _(countriesToMap).filter(haveEnoughDataToMap);
canDo.each(function asyncMappingProcess(countryData) {
var assistant = new MapMakingAssistant();
assistant.on("return", function(countryMap) {
self.done(countryData.id, countryMap);
});
assistant.run(countryData);
});
// Will return with the amount of data
// that is being processed immediately,
// while the actual processing will be
// running in the meantime.
return canDo.length;
});
// Call with:
var mapMaker = new Cartographist();
mapMaker.on("return", function(dataLength) {
giveSomeFeedbackMaybe("Making %s maps", dataLength);
});
mapMaker.on("done", function(countryId, countryMap) {
displayThisMap(countryId, countryMap);
});
mapMaker.run(someCountries);
Where can I find dyno.js?