Coder Social home page Coder Social logo

tart-membrane's Introduction

tart-membrane

Stability: 1 - Experimental

NPM version

Implementation of a membrane for Tiny Actor Run-Time in JavaScript.

Contributors

@dalnefre, @tristanls

Overview

An implementation of a membrane.

Usage

To run the below example run:

npm run readme
"use strict";

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

var sponsor = tart.minimal();


var aliceReport = function aliceReport(charlie) {
    return function aliceReportBeh(message) {
        var alice = this.self;
        console.log('alice received response from charlie');
        console.log('message.alice === alice:', message.alice === alice);
        console.log('message.charlie === charlie:', message.charlie === charlie);
    };
};

var aliceBeh = function aliceBeh(message) {
    var alice = this.self;
    // send charlie everything alice knows
    message.charlie({alice: alice, charlie: message.charlie});
    this.behavior = aliceReport(message.charlie);
};

var charlieBeh = function charlieBeh(message) {
    var charlie = this.self;
    // send alice everything charlie knows
    message.alice({alice: message.alice, charlie: charlie});
    console.log('charlie received message from alice');
    console.log('message.charlie === charlie:', message.charlie === charlie);
};

var alice = sponsor(aliceBeh);
var charlie = sponsor(charlieBeh);

var membraneBehs = membrane.behaviors();
var revokeMembrane = sponsor(membraneBehs.revokeBeh);

var charlieProxyBeh = membraneBehs.proxy(charlie);
var charlieProxy = sponsor(charlieProxyBeh);

// get alice to send message to charlie and report a response
alice({charlie: charlieProxy});

// alternatively, membrane factory pattern can be used

var membraneFactoryCaps = membrane.factory(sponsor);

var dennis = sponsor(function () {});
var dennisProxy1 = membraneFactoryCaps.proxy(dennis);
var dennisProxy2 = membraneFactoryCaps.proxy(dennis);
console.log('dennisProxy1 === dennisProxy2:', dennisProxy1 === dennisProxy2);

Tests

npm test

Documentation

Sources

tart-membrane's People

Contributors

tristanls avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.