import { logger } from '../podkop'; export async function withTimeout( promise: Promise, timeoutMs: number, operationName: string, timeoutMessage = _('Operation timed out'), ): Promise { let timeoutId; const start = performance.now(); const timeoutPromise = new Promise((_, reject) => { timeoutId = setTimeout(() => reject(new Error(timeoutMessage)), timeoutMs); }); try { return await Promise.race([promise, timeoutPromise]); } finally { clearTimeout(timeoutId); const elapsed = performance.now() - start; logger.info('[SHELL]', `[${operationName}] took ${elapsed.toFixed(2)} ms`); } }