How to use carrier - 10 common examples

To help you get started, we’ve selected a few carrier examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pgte / alfred / test / replication / test_slave_reconnect.js View on Github external
net.createServer(function(stream) {
        connects ++;
        if (max_connects == connects) {
          clearTimeout(timeout);
          next();
          return;
        }
        carrier.carry(stream, function(line) {
          assert.equal(line, '{"command":"sync"}');
          
          stream.end();
          
        });
      }).listen(5293); // default port
github anthonywebb / node-cbus / cgate.js View on Github external
// TELNET CHANNEL TO STATUS UPDATES
  statuses = net.createConnection(CONFIG.cgate.statusport,CONFIG.cgate.host);
  statuses.on('error', function(error){
      console.log('cgate statuses socket error: ' + error);
  });
  statuses.on('end', function(){
      console.log('cgate statuses socket terminated');
  });
  statuses.on('close', function(){
      console.log('cgate statuses socket closed');
  });
  statuses.on('timeout', function(){
      console.log('cgate statuses socket timed out');
  });
  carrier.carry(statuses, function(line) {
    pushRealtime('statusStream',line);
  });

  // every time that a message arrives, we need to send it out the realtime websocket
  function pushRealtime(type, message) {
    console.log(type+' : '+message);
    // every message, before being sent out needs to be parsed to create a nice object that can be consumed
    var parsedMessage = parseMessage(message,type);
    IO.emit(type, parsedMessage);
  }

  // periodically list the levels of all devices to make sure they are in sync
  setTimeout(syncLevels, 5000);
  // repeat every 20 mins
  setInterval(syncLevels, 1200000)
github anthonywebb / node-cbus / cgate.js View on Github external
// TELNET CHANNEL TO STATUS UPDATES
  events = net.createConnection(CONFIG.cgate.eventport,CONFIG.cgate.host);
  events.on('error', function(error){
      console.log('cgate events socket error: ' + error);
  });
  events.on('end', function(){
      console.log('cgate events socket terminated');
  });
  events.on('close', function(){
      console.log('cgate events socket closed');
  });
  events.on('timeout', function(){
      console.log('cgate events socket timed out');
  });
  carrier.carry(events, function(line) {
    pushRealtime('eventStream',line);
  });

  // TELNET CHANNEL TO STATUS UPDATES
  statuses = net.createConnection(CONFIG.cgate.statusport,CONFIG.cgate.host);
  statuses.on('error', function(error){
      console.log('cgate statuses socket error: ' + error);
  });
  statuses.on('end', function(){
      console.log('cgate statuses socket terminated');
  });
  statuses.on('close', function(){
      console.log('cgate statuses socket closed');
  });
  statuses.on('timeout', function(){
      console.log('cgate statuses socket timed out');
github anthonywebb / node-cbus / cgate.js View on Github external
exports.init = function(){
  // TELNET SESSION TO CONTROL
  control = net.createConnection(CONFIG.cgate.contolport,CONFIG.cgate.host);
  control.on('error', function(error){
      console.log('cgate control socket error: ' + error);
  });
  control.on('end', function(){
      console.log('cgate control socket terminated');
  });
  control.on('close', function(){
      console.log('cgate control socket closed');
  });
  control.on('timeout', function(){
      console.log('cgate control socket timed out');
  });
  carrier.carry(control, function(line) {
    pushRealtime('controlStream',line);
  });

  // TELNET CHANNEL TO STATUS UPDATES
  events = net.createConnection(CONFIG.cgate.eventport,CONFIG.cgate.host);
  events.on('error', function(error){
      console.log('cgate events socket error: ' + error);
  });
  events.on('end', function(){
      console.log('cgate events socket terminated');
  });
  events.on('close', function(){
      console.log('cgate events socket closed');
  });
  events.on('timeout', function(){
      console.log('cgate events socket timed out');
github victorquinn / memcache-plus / lib / connection.js View on Github external
self.client.on('connect', function() {
        self.emit('connect');
        debug('successfully (re)connected!');
        self.ready = true;
        // Reset backoff if we connect successfully
        self.backoff = 10;

        // If an onConnect handler was specified, execute it
        if (self.onConnect) {
            self.onConnect();
        }
        self.flushBuffer();
    });

    carrier.carry(self.client, self.read.bind(self));
};
github jessica-taylor / hashlattice / lib / mininet.js View on Github external
function Mininet(topology) {
  var self = this;
  self.hostToIP = null;
  self.hostToPorts = null;
  // TODO: pass topology as argument to mininet_client?
  var args = topology ? ['--topo', topology] : [];
  self.mn = ChildProcess.spawn('mn', args, {stdio: ['pipe', 'pipe', 'pipe']});
  self.mn.stdin.write('py sys.stderr.write("HOSTS " + __import__("json").dumps([{"name": h.name, "ip": h.IP(), "port": h.ports.values()} for h in net.hosts]) + "\\n")\n');
  var loggingAllLines = false;
  Carrier.carry(self.mn.stdout).on('line', function(line) {
    if (line.indexOf('mininet>') == -1) {
      console.warn(line);
    }
  });
  Carrier.carry(self.mn.stderr).on('line', function(line) {
    if (line.substring(0, 5) == 'HOSTS') {
      var hosts = JSON.parse(line.substring(6));
      self.hostToIP = {};
      self.hostToPorts = {};
      for (var i = 0; i < hosts.length; i++) {
        self.hostToIP[hosts[i].name] = hosts[i].ip;
        self.hostToPorts[hosts[i].name] = hosts[i].port;
      }
    } else {
      if (line.indexOf('Traceback') > -1) {
        loggingAllLines = true;
github jessica-taylor / hashlattice / lib / mininet.js View on Github external
function Mininet(topology) {
  var self = this;
  self.hostToIP = null;
  self.hostToPorts = null;
  // TODO: pass topology as argument to mininet_client?
  var args = topology ? ['--topo', topology] : [];
  self.mn = ChildProcess.spawn('mn', args, {stdio: ['pipe', 'pipe', 'pipe']});
  self.mn.stdin.write('py sys.stderr.write("HOSTS " + __import__("json").dumps([{"name": h.name, "ip": h.IP(), "port": h.ports.values()} for h in net.hosts]) + "\\n")\n');
  var loggingAllLines = false;
  Carrier.carry(self.mn.stdout).on('line', function(line) {
    if (line.indexOf('mininet>') == -1) {
      console.warn(line);
    }
  });
  Carrier.carry(self.mn.stderr).on('line', function(line) {
    if (line.substring(0, 5) == 'HOSTS') {
      var hosts = JSON.parse(line.substring(6));
      self.hostToIP = {};
      self.hostToPorts = {};
      for (var i = 0; i < hosts.length; i++) {
        self.hostToIP[hosts[i].name] = hosts[i].ip;
        self.hostToPorts[hosts[i].name] = hosts[i].port;
      }
    } else {
      if (line.indexOf('Traceback') > -1) {
        loggingAllLines = true;
      }
      if (loggingAllLines) {
        console.warn(line);
      }
    }
github robotty / dank-twitch-irc / lib / connection.ts View on Github external
if (line.length <= 0) {
                // ignore empty lines
                return;
            }
            this.log.trace('< ' + line);

            let ircMessage: IRCMessage | null = parseMessage(line);

            if (ircMessage == null) {
                this.log.warn('Ignoring invalid IRC message', line);
                return;
            }

            this.handleIRCMessage(ircMessage);
        };
        carrier.carry(this.socket, handleLine, 'utf-8');

        this.socket.on('secureConnect', () => {
            this._onConnect.dispatch();
        });

        this.socket.on('close', (hadError: boolean) => {
            this._onClose.dispatch(hadError);
        });

        this.socket.on('error', (e: Error) => {
            this._onError.dispatch(e);
        });

        // server-ping
        this.subscribe(PingMessage, (msg: PingMessage) => {
            if (msg.argument == null) {
github leanprover / vscode-lean / src / batch.ts View on Github external
editor: TextEditor,
    edit: TextEditorEdit,
    args: any[]) {
    batchOutputChannel = batchOutputChannel ||
        window.createOutputChannel('Lean: Batch File Output');

    const fileName = editor.document.fileName;

    const executablePath = server.executablePath;

    const lean = child.spawn(executablePath, [fileName],
        { cwd: workspace.rootPath, env: {} /* TODO(gabriel): take from server */ });

    batchOutputChannel.clear();

    carrier.carry(lean.stdout, (line) => {
        batchOutputChannel.appendLine(line);
    });

    carrier.carry(lean.stderr, (line) => {
        batchOutputChannel.appendLine(line);
    });

    lean.on('close', (code) => {
      /* not sure if we need to do anything here */
    });

    batchOutputChannel.show(true);
}
github leanprover / vscode-lean / src / batch.ts View on Github external
window.createOutputChannel('Lean: Batch File Output');

    const fileName = editor.document.fileName;

    const executablePath = server.executablePath;

    const lean = child.spawn(executablePath, [fileName],
        { cwd: workspace.rootPath, env: {} /* TODO(gabriel): take from server */ });

    batchOutputChannel.clear();

    carrier.carry(lean.stdout, (line) => {
        batchOutputChannel.appendLine(line);
    });

    carrier.carry(lean.stderr, (line) => {
        batchOutputChannel.appendLine(line);
    });

    lean.on('close', (code) => {
      /* not sure if we need to do anything here */
    });

    batchOutputChannel.show(true);
}

carrier

Evented stream line reader for node.js

MIT
Latest version published 9 years ago

Package Health Score

50 / 100
Full package analysis

Popular carrier functions