Next.js website for Rocky Mountain Vending company featuring: - Product catalog with Stripe integration - Service areas and parts pages - Admin dashboard with Clerk authentication - SEO optimized pages with JSON-LD structured data Co-authored-by: Cursor <cursoragent@cursor.com>
23 lines
1 KiB
Text
23 lines
1 KiB
Text
import { timing } from "./timing";
|
|
const DEFER_EVENT_LISTENER_TIME = 3000;
|
|
export const setSocketTimeout = (request, reject, timeoutInMs = 0) => {
|
|
const registerTimeout = (offset) => {
|
|
const timeout = timeoutInMs - offset;
|
|
const onTimeout = () => {
|
|
request.destroy();
|
|
reject(Object.assign(new Error(`@smithy/node-http-handler - the request socket timed out after ${timeoutInMs} ms of inactivity (configured by client requestHandler).`), { name: "TimeoutError" }));
|
|
};
|
|
if (request.socket) {
|
|
request.socket.setTimeout(timeout, onTimeout);
|
|
request.on("close", () => request.socket?.removeListener("timeout", onTimeout));
|
|
}
|
|
else {
|
|
request.setTimeout(timeout, onTimeout);
|
|
}
|
|
};
|
|
if (0 < timeoutInMs && timeoutInMs < 6000) {
|
|
registerTimeout(0);
|
|
return 0;
|
|
}
|
|
return timing.setTimeout(registerTimeout.bind(null, timeoutInMs === 0 ? 0 : DEFER_EVENT_LISTENER_TIME), DEFER_EVENT_LISTENER_TIME);
|
|
};
|