From c05933f652857aec6975c7c38418805d0171cb88 Mon Sep 17 00:00:00 2001 From: Joachim Van Herwegen Date: Thu, 11 Feb 2021 10:46:24 +0100 Subject: [PATCH] fix: Simply GuardedStream check --- src/util/GuardedStream.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/util/GuardedStream.ts b/src/util/GuardedStream.ts index d95b65de0..8efbc2479 100644 --- a/src/util/GuardedStream.ts +++ b/src/util/GuardedStream.ts @@ -36,9 +36,8 @@ export function isGuarded(stream: T): stream is G */ function guardingErrorListener(this: Guarded, error: Error): void { // Only fall back to this if no new listeners are attached since guarding started. - // Not storing the index when guarding starts since listeners could be removed. - const idx = this.listeners('error').indexOf(guardingErrorListener); - if (idx === this.listenerCount('error') - 1) { + const errorListeners = this.listeners('error'); + if (errorListeners[errorListeners.length - 1] === guardingErrorListener) { this[guardedErrors].push(error); if (!this[guardedTimeout]) { this[guardedTimeout] = setTimeout((): void => {