Skip to content

Commit 544d0a3

Browse files
committed
feat: 5 seconds timeout on get vscode ver
1 parent 059d39b commit 544d0a3

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

src/services/get-vscode-version.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
11
const FALLBACK = "1.98.1"
22

33
export async function getVSCodeVersion() {
4-
const response = await fetch(
5-
"https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=visual-studio-code-bin",
6-
)
4+
const controller = new AbortController()
5+
const timeout = setTimeout(() => {
6+
controller.abort()
7+
}, 5000)
78

8-
const pkgbuild = await response.text()
9-
const pkgverRegex = /pkgver=([0-9.]+)/
10-
const match = pkgbuild.match(pkgverRegex)
9+
try {
10+
const response = await fetch(
11+
"https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=visual-studio-code-bin",
12+
{ signal: controller.signal },
13+
)
1114

12-
if (match) {
13-
return match[1]
14-
}
15+
const pkgbuild = await response.text()
16+
const pkgverRegex = /pkgver=([0-9.]+)/
17+
const match = pkgbuild.match(pkgverRegex)
18+
19+
if (match) {
20+
return match[1]
21+
}
1522

16-
return FALLBACK
23+
return FALLBACK
24+
} catch {
25+
return FALLBACK
26+
} finally {
27+
clearTimeout(timeout)
28+
}
1729
}
1830

1931
await getVSCodeVersion()

0 commit comments

Comments
 (0)