tart-tracing
Stability: 1 - Experimental
Tracing configuration implementation for Tiny Actor Run-Time in JavaScript.
Contributors
Overview
Tracing configuration implementation for Tiny Actor Run-Time in JavaScript.
Usage
To run the below example run:
npm run readme
"use strict"; var tart = ;var util = ; var tracing = tart; var {};var {}; var { var actor = this; // create ; // send thisbehavior = becomeBeh; // become}; var actor = tracing;; var effect; console;console;while effect = tracing != false console; console;;console;console;
Tests
npm test
Documentation
Events
An event
is an abstraction around the concept of a message
being delivered to the actor. It is a tuple of a message
, context
, and cause
. When an event
is dispatched, the actor context
is bound to this
parameter and the behavior is executed given the message
. The result of processing the message
is an effect
.
An event
has the following attributes:
cause
: Event (Default: undefined) Theevent
that caused this event to happen. Will beundefined
if this event was not created in an actor behavior.context
: Object Actor context the message was delivered to.message
: Any Message that was delivered.
Effects
An effect
is an Object that is the effect of dispatching an event
. It has the following attributes:
became
: Function (Default: undefined)function (message) {}
If the actor changed its behavior as a result of processing amessage
, the new behavior it became is referenced here.behavior
: Function (Default: undefined)function (message) {}
The behavior that executed to cause thiseffect
, if any.created
: Array An array of created contexts. A context is the execution context of an actor behavior (the value of this when the behavior executes).event
: Object (Default: undefined) The event that is the cause of thiseffect
, if any.exception
: Error (Default: undefined) If dispatching theevent
caused an exception, that exception is stored here.sent
: Array An array ofevents
that represent messages sent by the actor as a result of processing amessage
.
Public API
tart.tracing(options)
options
: Object (Default: undefined) Optional overrides. WARNING: Implementation ofenqueue
anddequeue
are tightly coupled and should be overridden together.annotate
: Functionfunction (actor) {}
An optional method to wrap/modify newly-created actors.constructConfig
: Function (Default:function (options) {}
)function (options) {}
Configuration creation function that is givenoptions
. It should return a capabilityfunction (behavior) {}
to create new actors.enqueue
: Functionfunction (eventQueue, events){}
Function that enqueues the newevents
onto theeventQueue
in place, causing side-effects (Example:function (eventQueue, events){ Array.prototype.push.apply(eventQueue, events); }
).dequeue
: Functionfunction (eventQueue){}
Function that returns next event to be dispatched given aneventQueue
(Example:function (eventQueue){ return eventQueue.shift(); }
).
- Return: Object The tracing control object.
dispatch
: Functionfunction () {}
Function to call in order to dispatch a single event.eventLoop
: Functionfunction ([control]) {}
Function to call in order to dispatch multiple events.history
: Array An array of effects that represents the history of execution.effect
: Object Accumulated effects not yet committed to history.sponsor
: Functionfunction (behavior) {}
A capability to create new actors.
Returns the tracing control object.
tracing.dispatch()
- Return: Effect or
false
. Effect of dispatching the nextevent
orfalse
if no events exists for dispatch.
Dispatch the next event
.
var tart = ;var tracing = tart; var effect = tracingeffect;consoledireffect;while effect = tracing !== false consoledireffect;
tracing.eventLoop([control])
control
: Object (Default:undefined
) Optional overrides.count
: Number (Default:undefined
) Maximum number of events to dispatch, or unlimited ifundefined
.fail
: Functionfunction (exception) {}
Function called to report exceptions thrown from an actor behavior. Exceptions are thrown by default. (Example:function (exception) {/*ignore exceptions*/}
).log
: Functionfunction (effect) {}
Function called with every effect resulting from an event dispatch.
- Return: Boolean
true
if event queue is exhausted,false
otherwise.
Dispatch events in a manner provided by control
.
By default, calling tracing.eventLoop()
with no parameters dispatches all events in the event queue.
var tart = ;var tracing = tart; var actor = tracing;;;; tracing;// foo// bar// baz
tracing.sponsor(behavior)
behavior
: Functionfunction (message) {}
Actor behavior to invoke every time an actor receives a message.- Return: Function
function (message) {}
Actor reference in form of a capability that can be invoked to send the actor a message.
Creates a new (traceable) actor and returns the actor reference in form of a capability to send that actor a message.
var tart = ;var tracing = tart;var actor = tracing;