Skip to content

Commit

Permalink
fix: check "setMaxListeners" in react native (#1773)
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito authored Oct 18, 2023
1 parent f207368 commit f5f31fa
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/node/SetupServerApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit f5f31fa

Please sign in to comment.