From 3594b21738342d82ec8152604f6453f2a580124c Mon Sep 17 00:00:00 2001 From: Paolo Insogna Date: Thu, 9 Feb 2023 09:49:18 +0100 Subject: [PATCH] events: add hasListener method --- doc/api/events.md | 12 +++++++ lib/events.js | 25 ++++++++++++++ test/parallel/test-events-has-listener.js | 40 +++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 test/parallel/test-events-has-listener.js diff --git a/doc/api/events.md b/doc/api/events.md index 5f64fa1dec2a7a..e42873fc7c2979 100644 --- a/doc/api/events.md +++ b/doc/api/events.md @@ -646,6 +646,18 @@ Returns the current max listener value for the `EventEmitter` which is either set by [`emitter.setMaxListeners(n)`][] or defaults to [`events.defaultMaxListeners`][]. +### `emitter.hasListener(eventName, listener)` + + + +* `eventName` {string|symbol} The name of the event being checked +* `listener` {Function} The listener to check + +Returns `true` if the listener is already register for the event, +`false` otherwise. + ### `emitter.listenerCount(eventName)`