tart-checkpoint

0.1.0 • Public • Published

tart-checkpoint

Checkpointing configuration implementation for Tiny Actor Run-Time in JavaScript.

Contributors

@dalnefre, @tristanls

Overview

Checkpointing configuration implementation for Tiny Actor Run-Time in JavaScript.

Usage

To run the below example run:

npm run readme
"use strict";

var tart = require('../index.js');

var checkpoint = tart.checkpoint();

var oneTimeBeh = (function oneTimeBeh(message) {
    console.log('oneTimeBeh:', message);
    var becomeBeh = (function becomeBeh(message) {}).toString();
    var actor = this.sponsor((function createdBeh(message) {
        console.log('createdBeh:', message);
    }).toString()); // create
    actor(this.state.label); // send
    this.behavior = becomeBeh; // become
}).toString();

var actor = checkpoint.sponsor(oneTimeBeh, { label:'foo' });
actor('bar');

Tests

npm test

Documentation

Checkpoint objects are intended to be safely convertible to JSON and back again without loss of information.

Events

An event is an Object that represents a message sent to an actor.

An event has the following attributes:

  • domain: String URI identifying the domain that generated the event.
  • time: Number Date.now() timestamp when the event was generated.
  • seq: Number event sequence number, monotonically increasing within time.
  • message: String Transport-encoded message to be delivered.
  • token: String Transport token identifying the target actor.

Actors

An actor is an Object that represents a unique entity with state and behavior.

An actor has the following attributes:

  • state: String Transport-encoded object representing the actor's state.
  • behavior: String The actor's behavior function in source form.
  • token: String Transport token uniquely identifying this actor.

Effects

An effect is an Object that represents the result of processing an event.

An effect has the following attributes:

  • created: Object (Default: {}) A map from tokens to newly-created actors.
  • sent: Array (Default: []) An array of events representing newly-sent messages.
  • output: Array (Default: []) An array of transport-encoded messages to remote actors.
  • cause: Object (Default: undefined) The event that is the cause of this effect, if any.
  • update: Function (Default: undefined) The new state and behavior of the actor that caused this event.
  • exception: Object (Default: undefined) If dispatching the event caused an exception, that exception is stored here.

Public API

tart.checkpoint(options)

  • options: Object (Default: undefined) Optional overrides.
    • logEffect: Function function (effect, callback) {} Record effect, then call callback(error).
  • Return: Object The checkpoint control object.
    • domain: Object Marshal domain.
    • router: Object Router for marshal domain.
    • sponsor: Function function (behavior[, state[, token]]) {} A capability to create new actors with persistent state and optional identity.

Create a checkpoint control object.

Sources

Package Sidebar

Install

npm i tart-checkpoint

Weekly Downloads

2

Version

0.1.0

License

MIT

Last publish

Collaborators

  • tristanls