Skip to content

Commit

Permalink
Chore: remove async-sema
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Nov 26, 2024
1 parent f64fa20 commit 1513a24
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 56 deletions.
14 changes: 4 additions & 10 deletions Build/build-speedtest-domainset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { readFileIntoProcessedArray } from './lib/fetch-text-by-line';
import { DomainsetOutput } from './lib/create-file';
import { OUTPUT_SURGE_DIR } from './constants/dir';
import { createMemoizedPromise } from './lib/memo-promise';
import { Sema } from 'async-sema';
import { newQueue } from '@henrygd/queue';

const KEYWORDS = [
'Hong Kong',
Expand Down Expand Up @@ -136,7 +136,7 @@ const PREDEFINE_DOMAINS = [

];

const s = new Sema(2);
const s = newQueue(2);

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

await s.acquire();

const r = await $fetch(url, {
const data = await s.add<Array<{ url: string, host: string }>>(() => $fetch(url, {
headers: {
dnt: '1',
Referer: 'https://www.speedtest.net/',
Expand All @@ -170,9 +168,7 @@ async function querySpeedtestApi(keyword: string) {
: {})
},
timeout: 1000 * 60
});

const data: Array<{ url: string, host: string }> = await r.json();
}).then(res => res.json()));

return data.reduce<string[]>(
(prev, cur) => {
Expand All @@ -187,8 +183,6 @@ async function querySpeedtestApi(keyword: string) {
} catch (e) {
console.error(e);
return [];
} finally {
s.release();
}
}

Expand Down
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
"@ghostery/adblocker": "^2.1.1",
"@henrygd/queue": "^1.0.7",
"async-retry": "^1.3.3",
"async-sema": "^3.1.1",
"better-sqlite3": "^11.5.0",
"better-sqlite3": "^11.6.0",
"cacache": "^19.0.1",
"cacheable-lookup": "^6.1.0",
"ci-info": "^4.1.0",
Expand All @@ -35,7 +34,7 @@
"escape-string-regexp-node": "^1.0.2",
"fast-cidr-tools": "^0.3.1",
"fdir": "^6.4.2",
"foxact": "^0.2.41",
"foxact": "^0.2.42",
"hash-wasm": "^4.12.0",
"json-stringify-pretty-compact": "^3.0.0",
"make-fetch-happen": "^14.0.3",
Expand All @@ -62,7 +61,7 @@
"@types/dns2": "^2.0.9",
"@types/make-fetch-happen": "^10.0.4",
"@types/mocha": "^10.0.10",
"@types/node": "^22.9.3",
"@types/node": "^22.10.0",
"@types/node-fetch": "^2.6.12",
"@types/punycode": "^2.1.4",
"@types/tar-fs": "^2.0.4",
Expand All @@ -71,7 +70,7 @@
"eslint-config-sukka": "^6.12.0",
"eslint-formatter-sukka": "^6.12.0",
"expect": "^29.7.0",
"mitata": "^1.0.15",
"mitata": "^1.0.17",
"mocha": "^10.8.2",
"typescript": "^5.7.2"
},
Expand Down
74 changes: 33 additions & 41 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1513a24

Please sign in to comment.