/** * Apply timeout to a cache operation * @param promise Promise to apply timeout to * @param operationName Name of the operation for logging * @param tierIndex Index of the cache tier * @param timeout Timeout in milliseconds * @returns Promise with timeout applied */ export function applyTimeout( promise: Promise, operationName: string, tierIndex: number, timeout: number = 5000 ): Promise { return Promise.race([ promise, new Promise((_, reject) => { setTimeout(() => { reject(new Error(`Tier ${tierIndex} ${operationName} operation timed out after ${timeout}ms`)); }, timeout); }), ]); }