Skip to content

EventEmitter: Inconsistent handling of once() handlers #6873

Description

@Flarna
  • Version: 6.2.0 (with references to others)
  • Platform: Windows 64 bit
  • Subsystem: EventEmitter

It seems EventEmitter has an inconsistent handling of listeners installed via once().

I think #5564 was targeting this topic also but was closed because #6394 was merged.

Not sure if this is a but or intended - or if changing this is seen as breaking change or not.
If it is kept like it is I would vote for updating documentation accordingly.

Activity

  1. added
    eventsIssues and PRs related to EventEmitter and the events module.
    on May 19, 2016
  2. cjihrig commented on May 19, 2016

    @cjihrig
    Contributor

    It was decided in #6394 that the previous behavior was a bug, and therefor not a breaking change.

    What did you have in mind as a documentation update?

  3. Flarna commented on May 19, 2016

    @Flarna
    MemberAuthor

    #6394 has changed/corrected the behavior of signaling which listener has been removed via 'removeListener' event.
    The listeners() function has not been changed in #6394, it still returns the wrapped function.

    I think we should either document that listeners() is not returning the registered listener or correct it to actually return the listener.

  4. cjihrig commented on May 19, 2016

    @cjihrig
    Contributor

    Ah, yea, @addaleax pinged @omsmith about that in #5564 (comment).

  5. jasnell commented on May 19, 2016

    @jasnell
    Member

    to be honest, if we could do so in a way that didn't kill perf I'd be ok with listeners being modified to not return the wrapper given that the wrapper really is an internal implementation detail.

  6. added a commit that references this issue on May 19, 2016
    d667704
  7. Flarna commented on May 19, 2016

    @Flarna
    MemberAuthor

    Is it really proven that adding a simple unwrap in listeners() kills performance?

    I would wonder that listeners() is an API which is used in performance relevant code as it creates a copy of an array. Quite a lot work - for actually getting list of functions back which has maybe "wrong" entries inside in all node versions till now.

    Most use cases I have seen till now are in the end just interested in the size of the array which is available much cheaper using listenerCount() where whether copy nor unwrap is needed.

    Not sure if this is the right place to ask: But as this and #6394 are seen as bugs are there also ported back to Node 4?

  8. added a commit that references this issue on May 27, 2016
    b8a10d0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    eventsIssues and PRs related to EventEmitter and the events module.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions