How to use the events.EventEmitter function in events

To help you get started, we’ve selected a few events 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 nock / propagate / tests / index.js View on Github external
test('emit on source before destination', t => {
  t.plan(2)

  const source = new EventEmitter()
  const dest = new EventEmitter()

  // Set up test case for "propagate all"
  // `count` should have been incremented by handler on source when handler on dest is invoked
  let count = 0
  propagate(source, dest)
  source.on('event', () => {
    count++
  })
  dest.on('event', () => {
    t.equal(count, 1, 'emit on source first')
  })

  // Emit the events for assertion
  t.true(source.emit('event'))
})
github mikeal / bong-bong / components / bong-bong.js View on Github external
require('./apps/dropub.json'),
  require('./apps/stickers.json')
  // require('./apps/pixel-pad.json')
]

const bongBongInput = require('./bong-bong-input')
const bongBongText = require('./bong-bong-text')
const bongBongSettings = require('./bong-bong-settings')
const bongBongImage = require('./bong-bong-image')
const bongBongMore = require('./bong-bong-more')
const bongBongApp = require('./bong-bong-app')
const bongLogin = require('./login')

const tick = require('./timers')

const defaultStorage = new EventEmitter()
defaultStorage.get = key => localStorage[key]
defaultStorage.set = (key, value) => {
  localStorage[key] = value
  defaultStorage.emit(key, value)
}

const uuid = a => {
  return a ? (a ^ Math.random() * 16 >> a / 4).toString(16)
             : ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, uuid)
}

const instant = {behavior: 'instant'}

function findFrame (event) {
  let frames = document.getElementsByTagName('iframe')
  for (var i = 0; i < frames.length; i++) {
github felixge / node-ar-drone / test / unit / video / test-PngEncoder.js View on Github external
before: function() {
    this.fakeFfmpeg = new EventEmitter();

    this.fakeFfmpeg.stdin       = new EventEmitter();
    this.fakeFfmpeg.stdin.write = sinon.stub();
    this.fakeFfmpeg.stdin.end   = sinon.stub();

    this.fakeFfmpeg.stdout = {pipe: sinon.spy()};
    this.fakeFfmpeg.stderr = {pipe: sinon.spy()};

    this.fakeSpawn = sinon.stub();
    this.fakeSpawn.returns(this.fakeFfmpeg);

    this.fakePngSplitter = new EventEmitter();

    this.fakeFrameRate = 23;

    this.fakeBuffer1 = new Buffer('123');
    this.fakeBuffer2 = new Buffer('456');

    this.fakeLog = {};

    this.encoder = new PngEncoder({
      spawn       : this.fakeSpawn,
      frameRate   : this.fakeFrameRate,
      pngSplitter : this.fakePngSplitter,
      log         : this.fakeLog,
    });
  },
github Crizstian / cinema-microservice / movies-service / src / config / mongo.spec.js View on Github external
it('should emit db Object with an EventEmitter', (done) => {
    const mediator = new EventEmitter()

    mediator.on('db.ready', (db) => {
      db.admin().listDatabases((err, dbs) => {
        test.equal(null, err)
        test.ok(dbs.databases.length > 0)
        console.log(dbs.databases)
        db.close()
        done()
      })
    })

    mediator.on('db.error', (err) => {
      console.log(err)
    })

    mongo.connect(dbSettings, mediator)
github acacode / flamebird / server / utils / emitter.js View on Github external
const events = require('events')

const emitter = new events.EventEmitter()

emitter.once('killall', signal =>
  console.log('Killing all processes with signal ', signal)
)

emitter.setMaxListeners(50)

module.exports = emitter
github Frontify / frontify-boilerplate / node_modules / grunt-contrib-less / node_modules / less / lib / less / index.js View on Github external
if (typeof(options) === 'function') {
            callback = options;
            options = {};
        }

        var parser = new(less.Parser)(options),
            ee;

        if (callback) {
            parser.parse(input, function (e, root) {
                try { callback(e, root && root.toCSS && root.toCSS(options)); } 
                catch (err) { callback(err); }
            });
        } else {
            ee = new (require('events').EventEmitter)();

            process.nextTick(function () {
                parser.parse(input, function (e, root) {
                    if (e) { return ee.emit('error', e); }
                    try { ee.emit('success', root.toCSS(options)); } 
                    catch (err) { ee.emit('error', err); }
                });
            });
            return ee;
        }
    },
    formatError: function(ctx, options) {
github muxiangqiu / webserverless / packages / fc-express / src / server.spec.ts View on Github external
const makeRequest = () => {
    const ee: any = new events.EventEmitter();
    ee.path = '/foo';
    ee.method = 'post';
    ee.queries = { foo: 'bar' };
    ee.headers = {
        foo: 'bar'
    };
    return ee;
};
github blaise-io / xssnake / server / netcode / server.js View on Github external
xss.netcode.Server = function() {
    this.emitter = new events.EventEmitter();
    this.roomManager = new xss.room.ServerRoomManager(this);
    this.ws = this.start();
};
github embedly / embedly-node / lib / embedly.js View on Github external
this.services = function() {
    var services = new EventEmitter()
      , self = this

    services.start = function() {
      if (this.key) {
        log.warn('services isn\'t available using the pro endpoints')
      }
      if (typeof(this._services) == 'undefined') {
        var host = parse_host(self.host)

        simple_request(host, 'GET'
                      , '/1/services/javascript'
                      , {'User-Agent': self.user_agent, 'Host': host.hostname}
                      , self.timeout )
          .on('complete', function services_complete(response, data) {
            try {
              self._services = JSON.parse(data)