diff options
author | Chocobozzz <me@florianbigard.com> | 2022-08-08 10:42:08 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-08-09 09:18:07 +0200 |
commit | 5a921e7b74910414626bfc9672b857e987e3ebed (patch) | |
tree | f627e2ccc11c55bcba9e630951e72c5f94864c12 /shared/core-utils/common | |
parent | 5e2afe4290103bf0d54ae7b3e62781f2a00487c9 (diff) | |
download | PeerTube-5a921e7b74910414626bfc9672b857e987e3ebed.tar.gz PeerTube-5a921e7b74910414626bfc9672b857e987e3ebed.tar.zst PeerTube-5a921e7b74910414626bfc9672b857e987e3ebed.zip |
Move to bullmq
Diffstat (limited to 'shared/core-utils/common')
-rw-r--r-- | shared/core-utils/common/promises.ts | 15 |
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 | ||
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 | |||
9 | export { | 21 | export { |
10 | isPromise, | 22 | isPromise, |
11 | isCatchable | 23 | isCatchable, |
24 | timeoutPromise | ||
12 | } | 25 | } |