EventEmitter once()
NodeJS
Medium
3 views
Problem Description
Listen to an event only once and print count.
Output Format
Print integer.
Constraints
Emit twice but handler runs once.
Official Solution
const { EventEmitter } = require('events');
const ee = new EventEmitter();
let n = 0;
ee.once('meetcode', () => { n += 1; });
ee.emit('meetcode');
ee.emit('meetcode');
console.log(n);
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!