question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

EventEmitter interface inconsistent

See original GitHub issue

Describe the bug

EventEmitter interface is based on NodeJS events module.

core-event-emitter module returns custom EventEmitter class which does not implement interface and native emitter is not accessible (private).

So, it’s possible to have the following error when calling native emitter functions not implemented by custom emitter:

(node:89665) UnhandledPromiseRejectionWarning: TypeError: emitter.off is not a function

To Reproduce In my example I tried to call the off function of native emitter.

Expected behavior Either a typescript error must be thrown at compile time. Or off function of native emitter is available on custom class Or all native emitter function are available.

I can make the fix asap after best solution has been chosen:

  • re-write EventEmitter interface with custom class methods
  • add off method to custom class
  • expose native emitter from custom class.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
faustbriancommented, Apr 16, 2019

If you encounter an issue and already have a solution just submit a PR with it otherwise small issues like that will just be resolved.

0reactions
dlecancommented, Apr 16, 2019

@faustbrian thank you for fixing this quickly.

It would have been also great to discuss it a little bit more before.

1/ The done “bugfix” doesn’t really fix the underlying issue: the Ark emitter.EventEmitter type is not a NodeJS events.EventEmitter and several other methods are missing, such as removeAllListeners, listeners, addListener … These methods used to be available with eventemitter3, removed by #2329, which have introduced an API breaking change and have impacted our Unik-Name implementation of Ark core (see https://github.com/ArkEcosystem/AIPs/issues/70).

Another solution: emitter.EventEmitter could inherit from events.EventEmitter and override a few methods to update the max count of listeners.

2/ @nigui had already done a private fix when he described the issue. So a fix for this issue has been done twice. This can bee seen as “lost time”. Was this issue critical enough to fix it so quickly (5h)?

So, for the next time, can you please tell us:

  • either Ark team is not interested in external contributions
  • or interested by Github’s PRs with some code, without discussing

Thank you

Read more comments on GitHub >

github_iconTop Results From Across the Web

Narrowing down class methods, typing without extending or ...
Class 'ChildEmitter' incorrectly implements interface 'TypedEmitter'. Types of property 'on' are incompatible. Type '(eventName: string | symbol ...
Read more >
EventEmitters must behave appropriately if a handler raises ...
EventEmitter events are supposed to be a one-way communcation channel from the emitter to the handler. This paradigm breaks if the handler throws...
Read more >
typed-emitter - npm
Strictly typed event emitter interface for TypeScript. Code size: Zero bytes - Just the typings, no implementation. Use the default event ...
Read more >
On EventEmitter In node.js - Web Reflection
On EventEmitter In node.js · on() is a shortcut for addListener but there is no off() as removeListener's shortcut (inconsistent) · add/removeListener is...
Read more >
asyncly - Bountysource
I had a situation where something was inheriting from EventEmitter, ... Currently EventEmitter2 can't be assigned directly to a EventEmitter interface:
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found