Skip to content

Commit

Permalink
Merge pull request #1576 from nestjs/fix/openhandle-typeorm-health-in…
Browse files Browse the repository at this point in the history
…dicator

fix(health): open handle when using `pingCheck` in jest environment
  • Loading branch information
BrunnerLivio authored Nov 26, 2021
2 parents 4e92162 + 0d7b48e commit 98a6739
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions lib/utils/promise-timeout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@ export class TimeoutError extends Error {}
*
* @internal
*/
export const promiseTimeout = function(
export const promiseTimeout = function (
ms: number,
promise: Promise<any>,
): Promise<any> {
// Create a promise that rejects in <ms> milliseconds
let timeout = new Promise((_, reject) => {
let id = setTimeout(() => {
clearTimeout(id);
reject(new TimeoutError('Timed out in ' + ms + 'ms.'));
}, ms);
});

// Returns a race between our timeout and the passed in promise
return Promise.race([promise, timeout]);
let timer: NodeJS.Timeout;
return Promise.race([
promise,
new Promise(
(_, reject) =>
(timer = setTimeout(
() => reject(new TimeoutError(`Timed out in ${ms}ms.`)),
ms,
)),
),
]).finally(() => clearTimeout(timer));
};

0 comments on commit 98a6739

Please sign in to comment.