|
| 1 | +import { resolveTimerTimeoutMs } from "openclaw/plugin-sdk/number-runtime"; |
| 2 | + |
1 | 3 | // Compatibility constants for existing imports. Discord no longer enforces |
2 | 4 | // channel-owned listener or inbound run timeouts. |
3 | 5 | export const DISCORD_DEFAULT_LISTENER_TIMEOUT_MS = 120_000; |
@@ -43,9 +45,10 @@ export async function raceWithTimeout<T, U>(params: {
|
43 | 45 | timeoutMs: number; |
44 | 46 | onTimeout: () => U; |
45 | 47 | }): Promise<T | U> { |
| 48 | +const timeoutMs = resolveTimerTimeoutMs(params.timeoutMs, 1); |
46 | 49 | let timeoutTimer: ReturnType<typeof setTimeout> | undefined; |
47 | 50 | const timeoutPromise = new Promise<U>((resolve) => { |
48 | | -timeoutTimer = setTimeout(() => resolve(params.onTimeout()), Math.max(1, params.timeoutMs)); |
| 51 | +timeoutTimer = setTimeout(() => resolve(params.onTimeout()), timeoutMs); |
49 | 52 | timeoutTimer.unref?.(); |
50 | 53 | }); |
51 | 54 | try { |
@@ -62,16 +65,14 @@ export async function withAbortTimeout<T>(params: {
|
62 | 65 | createTimeoutError: () => Error; |
63 | 66 | run: (signal: AbortSignal) => Promise<T>; |
64 | 67 | }): Promise<T> { |
| 68 | +const timeoutMs = resolveTimerTimeoutMs(params.timeoutMs, 1); |
65 | 69 | const controller = new AbortController(); |
66 | 70 | let timeoutTimer: ReturnType<typeof setTimeout> | undefined; |
67 | 71 | const timeoutPromise = new Promise<never>((_, reject) => { |
68 | | -timeoutTimer = setTimeout( |
69 | | -() => { |
70 | | -controller.abort(); |
71 | | -reject(params.createTimeoutError()); |
72 | | -}, |
73 | | -Math.max(1, params.timeoutMs), |
74 | | -); |
| 72 | +timeoutTimer = setTimeout(() => { |
| 73 | +controller.abort(); |
| 74 | +reject(params.createTimeoutError()); |
| 75 | +}, timeoutMs); |
75 | 76 | timeoutTimer.unref?.(); |
76 | 77 | }); |
77 | 78 | try { |
|