Skip to content

Instantly share code, notes, and snippets.

@umidjons
Last active August 13, 2016 08:40
Show Gist options
  • Save umidjons/660872ebe7c5ee4872967f81ebead8c3 to your computer and use it in GitHub Desktop.
Save umidjons/660872ebe7c5ee4872967f81ebead8c3 to your computer and use it in GitHub Desktop.
EventEmitter example

events.EventEmitter example

"use strict";

var EventEmitter = require('events').EventEmitter;
var ee = new EventEmitter();
var counter = 1;

setInterval(function () {
    ee.emit('timed', counter++);
}, 3000);

ee.on('timed', function (data) {
    console.log('timed ' + data);
});

Sample output:

> node test
timed 1
timed 2
timed 3
^C
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment