Stability: 1 - Experimental
Behaving configuration implementation for Tiny Actor Run-Time in JavaScript that actors can send messages to.
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 viathis.config(message)
.constructConfig
: Function (Default:function (options) {}
)function (options) {}
Configuration creation function that is givenoptions
. It should return a capabilityfunction (behavior) {}
to create new actors.deliver
: Function (Default:function (context, message, options) {}
)function (context, message, options) {}
Deliver function that returns a function fordispatch
to dispatch.dispatch
: Function (Default:setImmediate
)function (deliver) {}
Dispatch function for dispatchingdeliver
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.
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
: Functionfunction (message) {}
Reference to the config that is sponsoring the executingbehavior
(in form of a capability that can be invoked to send the config a message).
Same as the core TartJS Minimal implementation. See: actor(message)