tart-behaving

Tart behaving

tart-behaving

Stability: 1 - Experimental

Behaving configuration implementation for Tiny Actor Run-Time in JavaScript that actors can send messages to.

@dalnefre, @tristanls

Behaving configuration implementation for Tiny Actor Run-Time in JavaScript that actors can send messages to.

To run the below example run:

npm run readme
"use strict";
 
var tart = require('../index.js');
 
var oneTimeLogBeh = function oneTimeLogBeh(message) {
    console.log('[logger]', message);
    this.behavior = function ignore(message) {};
};
 
var sponsor = tart.behaving({behavior: oneTimeLogBeh});
 
var someBeh = function someBeh(message) {
    var timestamp = new Date().getTime();
    this.config(timestamp);
    this.config(timestamp);
    message.customer('hi');
};
 
var customerBeh = function customerBeh(message) {
    console.log('customer:', message);
};
 
var actor = sponsor(someBeh);
var customer = sponsor(customerBeh);
 
actor({customer: customer});
npm test

Public API

  • options: Object (Default: undefined) Optional overrides.
    • behavior: Function (Default: function (message) {}) function (message) {} Configuration behavior to invoke every time a message is sent to the configuration via this.config(message).
    • constructConfig: Function (Default: function (options) {}) function (options) {} Configuration creation function that is given options. It should return a capability function (behavior) {} to create new actors.
    • deliver: Function (Default: function (context, message, options) {}) function (context, message, options) {} Deliver function that returns a function for dispatch to dispatch.
    • dispatch: Function (Default: setImmediate) function (deliver) {} Dispatch function for dispatching deliver closures.
    • fail: Function (Default: function (exception) {}) function (exception) {} An optional handler to call if a sponsored actor behavior throws an exception.

Creates a sponsor capability to create new actors with and allows replacing parts of the implementation. It is implemented on top of TartJS Pluggable API.

Same as the core TartJS Minimal implementation. See: sponsor(behavior)

Same as the core TartJS Minimal implementation. See: actor(message)