aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/core-utils
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-08-08 10:42:08 +0200
committerChocobozzz <me@florianbigard.com>2022-08-09 09:18:07 +0200
commit5a921e7b74910414626bfc9672b857e987e3ebed (patch)
treef627e2ccc11c55bcba9e630951e72c5f94864c12 /shared/core-utils
parent5e2afe4290103bf0d54ae7b3e62781f2a00487c9 (diff)
downloadPeerTube-5a921e7b74910414626bfc9672b857e987e3ebed.tar.gz
PeerTube-5a921e7b74910414626bfc9672b857e987e3ebed.tar.zst
PeerTube-5a921e7b74910414626bfc9672b857e987e3ebed.zip
Move to bullmq
Diffstat (limited to 'shared/core-utils')
-rw-r--r--shared/core-utils/common/promises.ts15
1 files changed, 14 insertions, 1 deletions
diff --git a/shared/core-utils/common/promises.ts b/shared/core-utils/common/promises.ts
index 7ef9d60b6..dc0db9074 100644
--- a/shared/core-utils/common/promises.ts
+++ b/shared/core-utils/common/promises.ts
@@ -6,7 +6,20 @@ function isCatchable (value: any) {
6 return value && typeof value.catch === 'function' 6 return value && typeof value.catch === 'function'
7} 7}
8 8
9function 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
9export { 21export {
10 isPromise, 22 isPromise,
11 isCatchable 23 isCatchable,
24 timeoutPromise
12} 25}