Giter Club home page Giter Club logo

node-await-event-emitter's Issues

Why do listeners also have to block/wait for each other?

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();

Export default

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! :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.