bot / node_modules /@aws-sdk /node-http-handler /dist-es /set-connection-timeout.js
sweet2004's picture
Upload 5577 files
80ce16c verified
Raw History Blame Contribute Delete
618 Bytes
export const setConnectionTimeout = (request, reject, timeoutInMs = 0) => {
if (!timeoutInMs) {
return;
}
request.on("socket", (socket) => {
if (socket.connecting) {
const timeoutId = setTimeout(() => {
request.destroy();
reject(Object.assign(new Error(`Socket timed out without establishing a connection within ${timeoutInMs} ms`), {
name: "TimeoutError",
}));
}, timeoutInMs);
socket.on("connect", () => {
clearTimeout(timeoutId);
});
}
});
};