Skip to content

Define a max number of listeners #1

@gil0mendes

Description

@gil0mendes

This can help developers who use Eventus find memory leaks in their code.


emitter.setMaxListeners(n)

By default EventEmitters will print a warning if more than 10 listeners are added for a particular event. This is a useful default which helps finding memory leaks. Obviously not all Emitters should be limited to 10. This function allows that to be increased. Set to zero for unlimited.

emitter.getMaxListeners()

Returns the current max listener value for the emitter which is either set by emitter.setMaxListeners(n) or defaults to EventEmitter.defaultMaxListeners.

This can be useful to increment/decrement max listeners to avoid the warning while not being irresponsible and setting a too big number.

Eventus.defaultMaxListeners

emitter.setMaxListeners(n) sets the maximum on a per-instance basis. This class property lets you set it for all Eventus instances, current and future, effective immediately. Use with care.

Note that emitter.setMaxListeners(n) still has precedence over Eventus.defaultMaxListeners.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions