control-rod-assembly

Control structure for connecting and disconnecting multiple ControlRods at once

control-rod-assembly

Stability: 1 - Experimental

Control structure for connecting and disconnecting multiple ControlRods at once.

var ControlRod = require('control-rod'),
    ControlRodAssembly = require('control-rod-assembly'),
    events = require('events');
 
var storage = new events.EventEmitter();
var publicserver = new events.EventEmitter();
var peerServer = new events.EventEmitter();
 
var rod1 = new ControlRod(storage, 'foo', function () { /* ... */ });
var rod2 = new ControlRod(storage, 'bar', function () { /* ... */ });
var rod3 = new ControlRod(publicserver, 'foo', function () { /* ... */ });
var rod4 = new ControlRod(publicserver, 'bar', function () { /* ... */ });
var rod5 = new ControlRod(peerServer, 'foo', function () { /* ... */ });
var rod6 = new ControlRod(peerServer, 'bar', function () { /* ... */ });
var rod7 = new ControlRod(peerServer, 'baz', function () { /* ... */ });
 
var rodAssembly = new ControlRodAssembly(rod1, rod2, rod3, rod4, rod5);
rodAssembly.add(rod6, rod7);
 
rodAssembly.on('connected', function () {
    console.log("assembly connected");
});
rodAssembly.on('disconnected', function () {
    console.log("assembly disconnected");
});
 
rodAssembly.connect();
// all rods are connected 
rodAssembly.disconnect();
// all rods are disconnected 
 
rodAssembly.rods();
// [rod1, rod2, rod3, rod4, rod5, rod6, rod7] array of rods in assembly 
npm test

ControlRodAssembly is an abstraction over a collection of ControlRods in order to connect and disconnect them together.

Public API

  • rod, [rod, ...]: ControlRod Zero, one, or more control rods to initialize with.

Creates a new instance of ControlRodAssembly.

  • rod, [rod, ...]: ControlRod Zero, one, or more control rods to add.

Adds specified ControlRods to assembly.

Connects all ControlRods in the assembly.

Disconnects all ControlRods in the assembly.

  • rod, [rod, ...]: ControlRod Zero, one, or more control rods to remove.

Removes specified ControlRods from assembly.

  • Return: Array An array of ControlRods in this assembly.
  • function () {}

Emitted once all the control rods in the assembly are connected.

  • function () {}

Emitted once all the control rods in the assembly are disconnected.