imcuttle / node-await-event-emitter Goto Github PK
View Code? Open in Web Editor NEWawait events library like EventEmitter
License: MIT License
await events library like EventEmitter
License: MIT License
Can I create a typescript version and PR?
Having emitter wait for all subscribers/listeners is quite useful however, I don't see a reason why multiple listeners have to block each other and executed in sequence (they should run independently). The listeners should run in parallel (i.e. Promise.all(listeners)).
(E.g. code below shows C being blocked until B is finished)
const AwaitEventEmitter = require('await-event-emitter').default
const emitter = new AwaitEventEmitter()
const tick = (name,args,time) =>
new Promise((resolve) => {
setTimeout(() => {
console.log(`${name} -${args}`);
resolve()
}, time || 1000)
})
emitter.on('event', async (args) => { await tick('A',args) });
emitter.on('event', async (args) => { await tick('B',args,4000) });
emitter.on('event', async (args) => { await tick('C',args) });
async function run() {
await emitter.emit('event', 'one')
await emitter.emit('event', 'two')
emitter.emitSync('event', 'three')
}
run();
Hi @imcuttle , I'm using your library and recently updated to the last version, and now I've started to get an issue on AwaitEventEmitter not been a constructor, this example from the README:
const AwaitEventEmitter = require('await-event-emitter')
const emitter = new AwaitEventEmitter()
Doesn't work anymore (at least on my project).
After some debug in order to make it work I had to add the default:
const AwaitEventEmitter = require('await-event-emitter').default
const emitter = new AwaitEventEmitter()
I'm not an expert, but I think this is because how the module is been exported:
exports.default = AwaitEventEmitter;
Instead of:
export default AwaitEventEmitter
As far I understand you moved to TS, so maybe this is related some compile configuration or something like that maybe?
I don't mind changing my code to include the missing .default
but you should check it and change the README in case this is not an issue.
BTW: Great job with this module! I totally loved it! :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.