Chore: remove async-sema

This commit is contained in:
SukkaW 2024-11-26 22:01:13 +08:00
parent f64fa201e9
commit 1513a24b8d
3 changed files with 41 additions and 56 deletions

View File

@ -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',
@ -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())
@ -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/',
@ -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) => {
@ -187,8 +183,6 @@ async function querySpeedtestApi(keyword: string) {
} catch (e) {
console.error(e);
return [];
} finally {
s.release();
}
}

View File

@ -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",
@ -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",
@ -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",
@ -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"
},

74
pnpm-lock.yaml generated
View File

@ -25,12 +25,9 @@ importers:
async-retry:
specifier: ^1.3.3
version: 1.3.3
async-sema:
specifier: ^3.1.1
version: 3.1.1
better-sqlite3:
specifier: ^11.5.0
version: 11.5.0
specifier: ^11.6.0
version: 11.6.0
cacache:
specifier: ^19.0.1
version: 19.0.1
@ -62,8 +59,8 @@ importers:
specifier: ^6.4.2
version: 6.4.2(picomatch@4.0.2)
foxact:
specifier: ^0.2.41
version: 0.2.41
specifier: ^0.2.42
version: 0.2.42
hash-wasm:
specifier: ^4.12.0
version: 4.12.0
@ -138,8 +135,8 @@ importers:
specifier: ^10.0.10
version: 10.0.10
'@types/node':
specifier: ^22.9.3
version: 22.9.3
specifier: ^22.10.0
version: 22.10.0
'@types/node-fetch':
specifier: ^2.6.12
version: 2.6.12
@ -165,8 +162,8 @@ importers:
specifier: ^29.7.0
version: 29.7.0
mitata:
specifier: ^1.0.15
version: 1.0.15
specifier: ^1.0.17
version: 1.0.17
mocha:
specifier: ^10.8.2
version: 10.8.2
@ -557,8 +554,8 @@ packages:
'@types/node-fetch@2.6.12':
resolution: {integrity: sha512-8nneRWKCg3rMtF69nLQJnOYUcbafYeFSjqkw3jCRLsqkWFlHaoQrr5mXmofFGOx3DKn7UfmBMyov8ySvLRVldA==}
'@types/node@22.9.3':
resolution: {integrity: sha512-F3u1fs/fce3FFk+DAxbxc78DF8x0cY09RRL8GnXLmkJ1jvx3TtPdWoTT5/NiYfI5ASqXBmfqJi9dZ3gxMx4lzw==}
'@types/node@22.10.0':
resolution: {integrity: sha512-XC70cRZVElFHfIUB40FgZOBbgJYFKKMa5nb9lxcwYstFG/Mi+/Y0bGS+rs6Dmhmkpq4pnNiLiuZAbc02YCOnmA==}
'@types/punycode@2.1.4':
resolution: {integrity: sha512-trzh6NzBnq8yw5e35f8xe8VTYjqM3NE7bohBtvDVf/dtUer3zYTLK1Ka3DG3p7bdtoaOHZucma6FfVKlQ134pQ==}
@ -697,9 +694,6 @@ packages:
async-retry@1.3.3:
resolution: {integrity: sha512-wfr/jstw9xNi/0teMHrRW7dsz3Lt5ARhYNZ2ewpadnhaIp5mbALhOAP+EAdsC7t4Z6wqsDVv9+W6gm1Dk9mEyw==}
async-sema@3.1.1:
resolution: {integrity: sha512-tLRNUXati5MFePdAk8dw7Qt7DpxPB60ofAgn8WRhW6a2rcimZnYBP9oxHiv0OHy+Wz7kPMG+t4LGdt31+4EmGg==}
asynckit@0.4.0:
resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==}
@ -727,8 +721,8 @@ packages:
base64-js@1.5.1:
resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==}
better-sqlite3@11.5.0:
resolution: {integrity: sha512-e/6eggfOutzoK0JWiU36jsisdWoHOfN9iWiW/SieKvb7SAa6aGNmBM/UKyp+/wWSXpLlWNN8tCPwoDNPhzUvuQ==}
better-sqlite3@11.6.0:
resolution: {integrity: sha512-2J6k/eVxcFYY2SsTxsXrj6XylzHWPxveCn4fKPKZFv/Vqn/Cd7lOuX4d7rGQXT5zL+97MkNL3nSbCrIoe3LkgA==}
binary-extensions@2.3.0:
resolution: {integrity: sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==}
@ -1156,8 +1150,8 @@ packages:
resolution: {integrity: sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==}
engines: {node: '>= 6'}
foxact@0.2.41:
resolution: {integrity: sha512-NgKsYRU6Dx4dHjZSlgO8AKrwsGuvrcCOqiPPLy+x6Nd9vBmRPq+JZjKWC5OcAVnISR1Bjn+Yg69UEdHEooJXDQ==}
foxact@0.2.42:
resolution: {integrity: sha512-dMlOuU2Yib3OiutdWTebmUy2io4RONE7bc5QZD9W7vM58p459PQ6UM2wxhakLiZnyCsEWdEXeJ9JPo6G5caFcA==}
peerDependencies:
react: '*'
peerDependenciesMeta:
@ -1461,8 +1455,8 @@ packages:
resolution: {integrity: sha512-umcy022ILvb5/3Djuu8LWeqUa8D68JaBzlttKeMWen48SjabqS3iY5w/vzeMzMUNhLDifyhbOwKDSznB1vvrwg==}
engines: {node: '>= 18'}
mitata@1.0.15:
resolution: {integrity: sha512-+Jf3UfqhZkf8r4y0mqgwMdC36D+mqn72eEYdgbMeihnAVDa3BSMN7xpyhgfpZMsZZoE4DxACNoftCk8Mur01IQ==}
mitata@1.0.17:
resolution: {integrity: sha512-luLuhHudcTm4vUV5O5MbHYc9nkCVxW50wO65lvSlrbvsov1KMsyv9njm9jIp5hWyJSiU9Nb+WQBeoSxwv6UraQ==}
mkdirp-classic@0.5.3:
resolution: {integrity: sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==}
@ -1855,8 +1849,8 @@ packages:
engines: {node: '>=14.17'}
hasBin: true
undici-types@6.19.8:
resolution: {integrity: sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==}
undici-types@6.20.0:
resolution: {integrity: sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==}
undici@6.21.0:
resolution: {integrity: sha512-BUgJXc752Kou3oOIuU1i+yZZypyZRqNPW0vqoMPl8VaoalSfeR0D8/t4iAS3yirs79SSMTxTag+ZC86uswv+Cw==}
@ -2098,7 +2092,7 @@ snapshots:
'@jest/schemas': 29.6.3
'@types/istanbul-lib-coverage': 2.0.6
'@types/istanbul-reports': 3.0.4
'@types/node': 22.9.3
'@types/node': 22.10.0
'@types/yargs': 17.0.33
chalk: 4.1.2
@ -2302,15 +2296,15 @@ snapshots:
'@types/better-sqlite3@7.6.12':
dependencies:
'@types/node': 22.9.3
'@types/node': 22.10.0
'@types/cacache@17.0.2':
dependencies:
'@types/node': 22.9.3
'@types/node': 22.10.0
'@types/dns2@2.0.9':
dependencies:
'@types/node': 22.9.3
'@types/node': 22.10.0
'@types/eslint@9.6.1':
dependencies:
@ -2341,12 +2335,12 @@ snapshots:
'@types/node-fetch@2.6.12':
dependencies:
'@types/node': 22.9.3
'@types/node': 22.10.0
form-data: 4.0.1
'@types/node@22.9.3':
'@types/node@22.10.0':
dependencies:
undici-types: 6.19.8
undici-types: 6.20.0
'@types/punycode@2.1.4': {}
@ -2354,18 +2348,18 @@ snapshots:
'@types/ssri@7.1.5':
dependencies:
'@types/node': 22.9.3
'@types/node': 22.10.0
'@types/stack-utils@2.0.3': {}
'@types/tar-fs@2.0.4':
dependencies:
'@types/node': 22.9.3
'@types/node': 22.10.0
'@types/tar-stream': 3.1.3
'@types/tar-stream@3.1.3':
dependencies:
'@types/node': 22.9.3
'@types/node': 22.10.0
'@types/yargs-parser@21.0.3': {}
@ -2499,8 +2493,6 @@ snapshots:
dependencies:
retry: 0.13.1
async-sema@3.1.1: {}
asynckit@0.4.0: {}
b4a@1.6.7: {}
@ -2532,7 +2524,7 @@ snapshots:
base64-js@1.5.1: {}
better-sqlite3@11.5.0:
better-sqlite3@11.6.0:
dependencies:
bindings: 1.5.0
prebuild-install: 7.1.2
@ -3026,7 +3018,7 @@ snapshots:
combined-stream: 1.0.8
mime-types: 2.1.35
foxact@0.2.41:
foxact@0.2.42:
dependencies:
client-only: 0.0.1
server-only: 0.0.1
@ -3202,7 +3194,7 @@ snapshots:
jest-util@29.7.0:
dependencies:
'@jest/types': 29.6.3
'@types/node': 22.9.3
'@types/node': 22.10.0
chalk: 4.1.2
ci-info: 3.9.0
graceful-fs: 4.2.11
@ -3335,7 +3327,7 @@ snapshots:
minipass: 7.1.2
rimraf: 5.0.10
mitata@1.0.15: {}
mitata@1.0.17: {}
mkdirp-classic@0.5.3: {}
@ -3754,7 +3746,7 @@ snapshots:
typescript@5.7.2: {}
undici-types@6.19.8: {}
undici-types@6.20.0: {}
undici@6.21.0(patch_hash=yuj5uy4vvwj67xoliq5togiyme): {}