Skip to content

Commit 1513a24

Browse files
committed
Chore: remove async-sema
1 parent f64fa20 commit 1513a24

File tree

3 files changed

+41
-56
lines changed

3 files changed

+41
-56
lines changed

Build/build-speedtest-domainset.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { readFileIntoProcessedArray } from './lib/fetch-text-by-line';
99
import { DomainsetOutput } from './lib/create-file';
1010
import { OUTPUT_SURGE_DIR } from './constants/dir';
1111
import { createMemoizedPromise } from './lib/memo-promise';
12-
import { Sema } from 'async-sema';
12+
import { newQueue } from '@henrygd/queue';
1313

1414
const KEYWORDS = [
1515
'Hong Kong',
@@ -136,7 +136,7 @@ const PREDEFINE_DOMAINS = [
136136

137137
];
138138

139-
const s = new Sema(2);
139+
const s = newQueue(2);
140140

141141
const latestTopUserAgentsPromise = $fetch('https://cdn.jsdelivr.net/npm/top-user-agents@latest/src/desktop.json')
142142
.then(res => res.json())
@@ -150,9 +150,7 @@ async function querySpeedtestApi(keyword: string) {
150150
try {
151151
const randomUserAgent = topUserAgents[Math.floor(Math.random() * topUserAgents.length)];
152152

153-
await s.acquire();
154-
155-
const r = await $fetch(url, {
153+
const data = await s.add<Array<{ url: string, host: string }>>(() => $fetch(url, {
156154
headers: {
157155
dnt: '1',
158156
Referer: 'https://www.speedtest.net/',
@@ -170,9 +168,7 @@ async function querySpeedtestApi(keyword: string) {
170168
: {})
171169
},
172170
timeout: 1000 * 60
173-
});
174-
175-
const data: Array<{ url: string, host: string }> = await r.json();
171+
}).then(res => res.json()));
176172

177173
return data.reduce<string[]>(
178174
(prev, cur) => {
@@ -187,8 +183,6 @@ async function querySpeedtestApi(keyword: string) {
187183
} catch (e) {
188184
console.error(e);
189185
return [];
190-
} finally {
191-
s.release();
192186
}
193187
}
194188

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
"@ghostery/adblocker": "^2.1.1",
2424
"@henrygd/queue": "^1.0.7",
2525
"async-retry": "^1.3.3",
26-
"async-sema": "^3.1.1",
27-
"better-sqlite3": "^11.5.0",
26+
"better-sqlite3": "^11.6.0",
2827
"cacache": "^19.0.1",
2928
"cacheable-lookup": "^6.1.0",
3029
"ci-info": "^4.1.0",
@@ -35,7 +34,7 @@
3534
"escape-string-regexp-node": "^1.0.2",
3635
"fast-cidr-tools": "^0.3.1",
3736
"fdir": "^6.4.2",
38-
"foxact": "^0.2.41",
37+
"foxact": "^0.2.42",
3938
"hash-wasm": "^4.12.0",
4039
"json-stringify-pretty-compact": "^3.0.0",
4140
"make-fetch-happen": "^14.0.3",
@@ -62,7 +61,7 @@
6261
"@types/dns2": "^2.0.9",
6362
"@types/make-fetch-happen": "^10.0.4",
6463
"@types/mocha": "^10.0.10",
65-
"@types/node": "^22.9.3",
64+
"@types/node": "^22.10.0",
6665
"@types/node-fetch": "^2.6.12",
6766
"@types/punycode": "^2.1.4",
6867
"@types/tar-fs": "^2.0.4",
@@ -71,7 +70,7 @@
7170
"eslint-config-sukka": "^6.12.0",
7271
"eslint-formatter-sukka": "^6.12.0",
7372
"expect": "^29.7.0",
74-
"mitata": "^1.0.15",
73+
"mitata": "^1.0.17",
7574
"mocha": "^10.8.2",
7675
"typescript": "^5.7.2"
7776
},

pnpm-lock.yaml

Lines changed: 33 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)