metarhia / metasync

Asynchronous Programming Library for JavaScript & Node.js
https://metarhia.com
MIT License
205 stars 35 forks source link

AsyncEmitter #427

Open tshemsedinov opened 5 years ago

tshemsedinov commented 5 years ago
ee.on('e1', async () => true);
await ee.emit('a1');

I suppose we need to hide counters when waiting for multiple event handlers to this abstraction.

tshemsedinov commented 5 years ago

I added tests that reveal problems and now it’s clear that we need to change data structure for wrappers. Maybe better store them mixed to functions: fn[symbolWrapper] = wrapper ? @nechaido @belochub @lundibundi

tshemsedinov commented 5 years ago

Implemented in a different way. Now we hold on and once in different data structures for each event separately:

AsyncEmitter {
  events:
    Map {
      'eventName' => {
        on: Set { listener<Function> },
        once: Map { listener<Function> => wrapper<Function> }
      },
  }
}

@nechaido @belochub @lundibundi