refactor: make timeout a utility function
This commit is contained in:
parent
9e03b62a59
commit
bda8007cdf
|
@ -136,7 +136,7 @@ export class RegistryService {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
this.sendRegistryRequest(pk);
|
this.sendRegistryRequest(pk);
|
||||||
await new Promise((resolve) => setTimeout(resolve, 200));
|
await pTimeout(200);
|
||||||
return this.getFromDB(pk);
|
return this.getFromDB(pk);
|
||||||
} else {
|
} else {
|
||||||
this.sendRegistryRequest(pk);
|
this.sendRegistryRequest(pk);
|
||||||
|
@ -145,14 +145,14 @@ export class RegistryService {
|
||||||
if (res === null) {
|
if (res === null) {
|
||||||
this.logger.verbose(`[registry] get (clean) ${key}`);
|
this.logger.verbose(`[registry] get (clean) ${key}`);
|
||||||
for (let i = 0; i < 200; i++) {
|
for (let i = 0; i < 200; i++) {
|
||||||
await new Promise((resolve) => setTimeout(resolve, 10));
|
await pTimeout(10);
|
||||||
if ((await this.getFromDB(pk)) !== null) {
|
if ((await this.getFromDB(pk)) !== null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.logger.verbose(`[registry] get (cached) ${key}`);
|
this.logger.verbose(`[registry] get (cached) ${key}`);
|
||||||
await new Promise((resolve) => setTimeout(resolve, 200));
|
await pTimeout(200);
|
||||||
}
|
}
|
||||||
return this.getFromDB(pk);
|
return this.getFromDB(pk);
|
||||||
}
|
}
|
||||||
|
@ -240,3 +240,7 @@ export class RegistryService {
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function pTimeout(ms: number) {
|
||||||
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue