const events = require("events");
function createEmitter(onOpen, onClose) {
const emiter = new events.EventEmitter()
emiter.once("open", onOpen)
emiter.once("close", onClose)
return emiter
}
function opened(emitter) {
emitter.emit('open')
}
function closed(emitter) {
emitter.emit('close')
}
let emitter = createEmitter(
() => console.log("Opened!"), () => console.log("Closed!")
);
opened(emitter);
closed(emitter);
module.exports.createEmitter = createEmitter;
module.exports.opened = opened;
module.exports.closed = closed;
No comments:
Post a Comment