Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

eventEmitter.removeListener calls removed listener within emit cycle #7872

@RGBboy

Description

@RGBboy

I am trying to remove an event listener during the emit cycle of an event. I would have thought the following code would not fail. Am I right in this assumption or should all of these event listeners be called?

  var emitter = new EventEmitter();

  t.plan(2);

  function one () {
    t.ok('called');
    emitter.removeListener('test', two);
  };

  function two () {
    t.fail('should not be called');
  };

  function three () {
    t.ok('called');
  };

  emitter.on('test', one);
  emitter.on('test', two);
  emitter.on('test', three);

  emitter.emit('test');

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions