# Code coverage report for lib/utils/bus.js

## Statements: 71.43% (10 / 14) Branches: 50% (1 / 2) Functions: 33.33% (1 / 3) Lines: 71.43% (10 / 14)

All files » lib/utils/ » bus.js

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    291
    1

    1
    1

    1

    1

    1

    1

    1

    1'use strict';
    var events = require('events'),
        util = require('util');

    var Bus = function () {
      events.EventEmitter.call(this);
    };

    util.inherits(Bus, events.EventEmitter);

    var bus = new Bus();

    // proxy process messages (if forked) to the bus
    process.on('message', function (event) {
      bus.emit(event);
    });

    var emit = bus.emit;

    // if nodemon was spawned via a fork, allow upstream communication
    // via process.send
    Iif (process.send) {
      bus.emit = function (event, data) {
        process.send({ type: event, data: data });
        emit.apply(bus, arguments);
      };
    }

    module.exports = bus;