template-saas/apps/backend/node_modules/@smithy/node-http-handler/dist-es/set-connection-timeout.js
rckrdmrd 50a821a415
Some checks failed
CI / Backend CI (push) Has been cancelled
CI / Frontend CI (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / CI Summary (push) Has been cancelled
[SIMCO-V38] feat: Actualizar a SIMCO v3.8.0
- HERENCIA-SIMCO.md actualizado con directivas v3.7 y v3.8
- Actualizaciones de configuracion

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 08:53:08 -06:00

37 lines
1.2 KiB
JavaScript

import { timing } from "./timing";
const DEFER_EVENT_LISTENER_TIME = 1000;
export const setConnectionTimeout = (request, reject, timeoutInMs = 0) => {
if (!timeoutInMs) {
return -1;
}
const registerTimeout = (offset) => {
const timeoutId = timing.setTimeout(() => {
request.destroy();
reject(Object.assign(new Error(`@smithy/node-http-handler - the request socket did not establish a connection with the server within the configured timeout of ${timeoutInMs} ms.`), {
name: "TimeoutError",
}));
}, timeoutInMs - offset);
const doWithSocket = (socket) => {
if (socket?.connecting) {
socket.on("connect", () => {
timing.clearTimeout(timeoutId);
});
}
else {
timing.clearTimeout(timeoutId);
}
};
if (request.socket) {
doWithSocket(request.socket);
}
else {
request.on("socket", doWithSocket);
}
};
if (timeoutInMs < 2000) {
registerTimeout(0);
return 0;
}
return timing.setTimeout(registerTimeout.bind(null, DEFER_EVENT_LISTENER_TIME), DEFER_EVENT_LISTENER_TIME);
};