mirror of
https://github.com/hexboy/maven-mirror-tool.git
synced 2026-07-09 17:28:25 +00:00
refactor: replace Promise.race with Promise.any in server check logic
This commit is contained in:
parent
c4ae2e1c7a
commit
4adc5adaba
1 changed files with 6 additions and 11 deletions
|
|
@ -82,20 +82,15 @@ export class GotDownloader {
|
|||
const { signal } = controller;
|
||||
|
||||
const requests = REPOSITORIES.map(async (srv, index) => {
|
||||
try {
|
||||
await this.checkServer(url, srv, signal);
|
||||
// Abort all other requests as soon as we get the first success
|
||||
controller.abort();
|
||||
this.pickedServer.set(url, index);
|
||||
return srv;
|
||||
} catch {
|
||||
// If the request was aborted, or failed (network error, timeout, etc.), return null
|
||||
return null;
|
||||
}
|
||||
await this.checkServer(url, srv, signal);
|
||||
// Abort all other requests as soon as we get the first success
|
||||
controller.abort();
|
||||
this.pickedServer.set(url, index);
|
||||
return srv;
|
||||
});
|
||||
|
||||
try {
|
||||
return await Promise.race(requests);
|
||||
return await Promise.any(requests);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue