main
|
Last change
on this file was 81bc7da, checked in by Klimentina Efremova <klimentina08642@…>, 3 months ago |
|
Initial commit
|
-
Property mode
set to
100644
|
|
File size:
946 bytes
|
| Line | |
|---|
| 1 | var events = require('events');
|
|---|
| 2 | var debug = require('debug')('nodemon');
|
|---|
| 3 | var util = require('util');
|
|---|
| 4 |
|
|---|
| 5 | var Bus = function () {
|
|---|
| 6 | events.EventEmitter.call(this);
|
|---|
| 7 | };
|
|---|
| 8 |
|
|---|
| 9 | util.inherits(Bus, events.EventEmitter);
|
|---|
| 10 |
|
|---|
| 11 | var bus = new Bus();
|
|---|
| 12 |
|
|---|
| 13 | // /*
|
|---|
| 14 | var collected = {};
|
|---|
| 15 | bus.on('newListener', function (event) {
|
|---|
| 16 | debug('bus new listener: %s (%s)', event, bus.listeners(event).length);
|
|---|
| 17 | if (!collected[event]) {
|
|---|
| 18 | collected[event] = true;
|
|---|
| 19 | bus.on(event, function () {
|
|---|
| 20 | debug('bus emit: %s', event);
|
|---|
| 21 | });
|
|---|
| 22 | }
|
|---|
| 23 | });
|
|---|
| 24 |
|
|---|
| 25 | // */
|
|---|
| 26 |
|
|---|
| 27 | // proxy process messages (if forked) to the bus
|
|---|
| 28 | process.on('message', function (event) {
|
|---|
| 29 | debug('process.message(%s)', event);
|
|---|
| 30 | bus.emit(event);
|
|---|
| 31 | });
|
|---|
| 32 |
|
|---|
| 33 | var emit = bus.emit;
|
|---|
| 34 |
|
|---|
| 35 | // if nodemon was spawned via a fork, allow upstream communication
|
|---|
| 36 | // via process.send
|
|---|
| 37 | if (process.send) {
|
|---|
| 38 | bus.emit = function (event, data) {
|
|---|
| 39 | process.send({ type: event, data: data });
|
|---|
| 40 | emit.apply(bus, arguments);
|
|---|
| 41 | };
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | module.exports = bus;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.