Skip to content

tristanls/tart-behaving

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tart-behaving

Stability: 1 - Experimental

NPM version

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

Contributors

@dalnefre, @tristanls

Overview

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

Usage

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});

Tests

npm test

Documentation

Public API

tart.behaving([options])

  • 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.

sponsor(behavior)

Similar to the core TartJS Minimal implementation (See: sponsor(behavior)) with the following addition.

When the behavior is invoked upon the receipt of a message, it's this will be additionally bound with:

  • this.config: Function function (message) {} Reference to the config that is sponsoring the executing behavior (in form of a capability that can be invoked to send the config a message).

actor(message)

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

Sources