]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/core-utils/common/promises.ts
Put private videos under a specific subdirectory
[github/Chocobozzz/PeerTube.git] / shared / core-utils / common / promises.ts
1 function isPromise (value: any) {
2 return value && typeof value.then === 'function'
3 }
4
5 function isCatchable (value: any) {
6 return value && typeof value.catch === 'function'
7 }
8
9 function timeoutPromise <T> (promise: Promise<T>, timeoutMs: number) {
10 let timer: ReturnType<typeof setTimeout>
11
12 return Promise.race([
13 promise,
14
15 new Promise((_res, rej) => {
16 timer = setTimeout(() => rej(new Error('Timeout')), timeoutMs)
17 })
18 ]).finally(() => clearTimeout(timer))
19 }
20
21 export {
22 isPromise,
23 isCatchable,
24 timeoutPromise
25 }