function isPromise (value: T | Promise): value is Promise { return value && typeof (value as Promise).then === 'function' } function isCatchable (value: any) { return value && typeof value.catch === 'function' } function timeoutPromise (promise: Promise, timeoutMs: number) { let timer: ReturnType return Promise.race([ promise, new Promise((_res, rej) => { timer = setTimeout(() => rej(new Error('Timeout')), timeoutMs) }) ]).finally(() => clearTimeout(timer)) } export { isPromise, isCatchable, timeoutPromise }