From f711273e6aa3e10a1588f7422241033067de45ff Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Tue, 17 Oct 2023 18:01:06 +0200 Subject: [PATCH] fix: check "setMaxListeners" in react native --- src/node/SetupServerApi.ts | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/node/SetupServerApi.ts b/src/node/SetupServerApi.ts index ebacb5c57..557ce47b5 100644 --- a/src/node/SetupServerApi.ts +++ b/src/node/SetupServerApi.ts @@ -51,17 +51,22 @@ export class SetupServerApi */ private init(): void { this.interceptor.on('request', async ({ request, requestId }) => { - // Bump the maximum number of event listeners on the - // request's "AbortSignal". This prepares the request - // for each request handler cloning it at least once. - // Note that cloning a request automatically appends a - // new "abort" event listener to the parent request's - // "AbortController" so if the parent aborts, all the - // clones are automatically aborted. - setMaxListeners( - Math.max(defaultMaxListeners, this.currentHandlers.length), - request.signal, - ) + /** + * @note React Native doesn't have "node:events". + */ + if (typeof setMaxListeners === 'function') { + // Bump the maximum number of event listeners on the + // request's "AbortSignal". This prepares the request + // for each request handler cloning it at least once. + // Note that cloning a request automatically appends a + // new "abort" event listener to the parent request's + // "AbortController" so if the parent aborts, all the + // clones are automatically aborted. + setMaxListeners( + Math.max(defaultMaxListeners, this.currentHandlers.length), + request.signal, + ) + } const response = await handleRequest( request,