{"version":3,"file":"withTimeout.mjs","sources":["../../../../src/services/mcp/utils/withTimeout.ts"],"sourcesContent":["/**\n * Wraps a promise with a timeout to prevent hanging operations.\n * The internal timer is always cleared once the race settles, preventing\n * ref'd timer handles from keeping the event loop alive after the operation completes.\n */\nexport const withTimeout = (\n promise: Promise,\n timeoutMs: number,\n operation: string\n): Promise => {\n let timeoutId: ReturnType;\n\n const timeoutPromise = new Promise((_, reject) => {\n timeoutId = setTimeout(() => {\n reject(new Error(`Operation '${operation}' timed out after ${timeoutMs}ms`));\n }, timeoutMs);\n });\n\n return Promise.race([promise, timeoutPromise]).finally(() => {\n clearTimeout(timeoutId);\n });\n};\n"],"names":["withTimeout","promise","timeoutMs","operation","timeoutId","timeoutPromise","Promise","_","reject","setTimeout","Error","race","finally","clearTimeout"],"mappings":"AAAA;;;;AAIC,IACM,MAAMA,WAAAA,GAAc,CACzBC,SACAC,SAAAA,EACAC,SAAAA,GAAAA;IAEA,IAAIC,SAAAA;AAEJ,IAAA,MAAMC,cAAAA,GAAiB,IAAIC,OAAAA,CAAW,CAACC,CAAAA,EAAGC,MAAAA,GAAAA;AACxCJ,QAAAA,SAAAA,GAAYK,UAAAA,CAAW,IAAA;YACrBD,MAAAA,CAAO,IAAIE,KAAAA,CAAM,CAAC,WAAW,EAAEP,UAAU,kBAAkB,EAAED,SAAAA,CAAU,EAAE,CAAC,CAAA,CAAA;QAC5E,CAAA,EAAGA,SAAAA,CAAAA;AACL,IAAA,CAAA,CAAA;IAEA,OAAOI,OAAAA,CAAQK,IAAI,CAAC;AAACV,QAAAA,OAAAA;AAASI,QAAAA;AAAe,KAAA,CAAA,CAAEO,OAAO,CAAC,IAAA;QACrDC,YAAAA,CAAaT,SAAAA,CAAAA;AACf,IAAA,CAAA,CAAA;AACF;;;;"}