diff --git a/src/service/registry.ts b/src/service/registry.ts index 95aca55..64957be 100644 --- a/src/service/registry.ts +++ b/src/service/registry.ts @@ -136,7 +136,7 @@ export class RegistryService { return res; } this.sendRegistryRequest(pk); - await new Promise((resolve) => setTimeout(resolve, 200)); + await pTimeout(200); return this.getFromDB(pk); } else { this.sendRegistryRequest(pk); @@ -145,14 +145,14 @@ export class RegistryService { if (res === null) { this.logger.verbose(`[registry] get (clean) ${key}`); for (let i = 0; i < 200; i++) { - await new Promise((resolve) => setTimeout(resolve, 10)); + await pTimeout(10); if ((await this.getFromDB(pk)) !== null) { break; } } } else { this.logger.verbose(`[registry] get (cached) ${key}`); - await new Promise((resolve) => setTimeout(resolve, 200)); + await pTimeout(200); } return this.getFromDB(pk); } @@ -240,3 +240,7 @@ export class RegistryService { ]); } } + +async function pTimeout(ms: number) { + return new Promise((resolve) => setTimeout(resolve, ms)); +}