Our EventEmitter in PhantomSQL is based on NodeJS version so they should be compatible. Here are couple examples on how to use the emitter.

Basic usage of registering and listening to an event.

"use strict";
const {EventEmitter} = require('events');
// Dump all the args
em.on('hello-event', (...arg)=> {"Hello event handler : " + arg)});
// Handler without args
em.on('hello-event', ()=> {"Another handler")});
// passed in arguments
em.on('hello-event', (id, val)=> {"Handler :"+id +", "+ val)});
// emit event
em.emit('hello-event', 123, 'ABC');

A more typical example would be to extend via prototype.

"use strict";
const {EventEmitter} = require('events');
function HelloService()
	// Extends via prototype
	Object.setPrototypeOf(HelloService.prototype, EventEmitter.prototype);
	this.hello = function()
	{"Hello service called");
const service = new HelloService();
service.on('hello', ()=> {"Hello Handler called")});

Leave a Reply

Your email address will not be published. Required fields are marked *

* Copy This Password *

* Type Or Paste Password Here *