Skip to content

Commit

Permalink
Processed code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrutter committed Jan 30, 2025
1 parent f240ec2 commit 8e7820f
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions source/core/timed-out.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ export default function timedOut(request: ClientRequest, delays: Delays, options
request[reentry] = true;
const cancelers: Array<typeof noop> = [];
const {once, unhandleAll} = unhandler();
const handled: Record<string, boolean> = {};
const handled: Map<string, boolean> = new Map<string, boolean>();

const addTimeout = (delay: number, callback: (delay: number, event: string) => void, event: string): (typeof noop) => {
const timeout = setTimeout(callback, delay, delay, event) as unknown as NodeJS.Timeout;

timeout.unref?.();

const cancel = (): void => {
handled[event] = true;
handled.set(event, true);
clearTimeout(timeout);
};

Expand All @@ -71,11 +71,13 @@ export default function timedOut(request: ClientRequest, delays: Delays, options
const {host, hostname} = options;

const timeoutHandler = (delay: number, event: string): void => {
setTimeout(() => {
if (!handled[event]) {
// Use queueMicroTask to allow for any cancelled events to be handled first,

Check failure on line 74 in source/core/timed-out.ts

View workflow job for this annotation

GitHub Actions / Node.js 20 on macos-latest

Trailing spaces not allowed.
// to prevent firing any TimeoutError unneeded when the event loop is busy or blocked
queueMicrotask(() => {
if (!handled.has(event)) {
request.destroy(new TimeoutError(delay, event));
}
}, 0);
});
};

const cancelTimeouts = (): void => {
Expand Down

0 comments on commit 8e7820f

Please sign in to comment.