Skip to content

Commit

Permalink
fix: limit promise concurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
amtrack committed Nov 21, 2023
1 parent 2aadfc9 commit da68f1e
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version-file: .node-version
- name: Install dependencies
run: yarn install
- name: Build
run: yarn build
env:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
## Development

```
yarn install
export GITHUB_TOKEN=xxx
yarn build
yarn develop
```
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"author": "Matthias Rolke <[email protected]>",
"license": "MIT",
"devDependencies": {
"p-limit": "5.0.0",
"serve": "14.2.1"
},
"scripts": {
Expand Down
4 changes: 3 additions & 1 deletion scripts/add-stars.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { mkdir, readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
import pLimit from "p-limit";

function getGitHubSlug(repositoryUrl) {
if (repositoryUrl === undefined) {
Expand Down Expand Up @@ -42,8 +43,9 @@ async function addStarsToPackage(pkg) {
}

async function addStarsToPackages(packages) {
const limit = pLimit(10);
const result = await Promise.all(
packages.map((pkg) => addStarsToPackage(pkg))
packages.map((pkg) => limit(() => addStarsToPackage(pkg)))
);
return result;
}
Expand Down
4 changes: 3 additions & 1 deletion scripts/get-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { mkdir, readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
import pLimit from "p-limit";

async function getManifest(plugin) {
let result;
Expand All @@ -18,7 +19,8 @@ async function getManifest(plugin) {
}

async function getCommands(plugins) {
const promises = plugins.map((plugin) => getManifest(plugin));
const limit = pLimit(50);
const promises = plugins.map((plugin) => limit(() => getManifest(plugin)));
const manifests = await Promise.all(promises);
const commands = manifests
.map((manifest) => Object.values(manifest?.commands || {}))
Expand Down
4 changes: 3 additions & 1 deletion scripts/get-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { mkdir, writeFile } from "node:fs/promises";
import { join } from "node:path";
import pLimit from "p-limit";

const additionalPackages = [];
const ignoredPackages = [];
Expand All @@ -25,7 +26,8 @@ async function getPackage(packageName) {
}

async function getPackages(packageNames) {
const promises = packageNames.map((p) => getPackage(p));
const limit = pLimit(50);
const promises = packageNames.map((p) => limit(() => getPackage(p)));
const packages = await Promise.all(promises);
return packages;
}
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,13 @@ onetime@^5.1.2:
dependencies:
mimic-fn "^2.1.0"

[email protected]:
version "5.0.0"
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-5.0.0.tgz#6946d5b7140b649b7a33a027d89b4c625b3a5985"
integrity sha512-/Eaoq+QyLSiXQ4lyYV23f14mZRQcXnxfHrN0vCai+ak9G0pp9iEQukIIZq5NccEvwRB8PUnZT0KsOoDCINS1qQ==
dependencies:
yocto-queue "^1.0.0"

[email protected]:
version "1.0.2"
resolved "https://registry.yarnpkg.com/path-is-inside/-/path-is-inside-1.0.2.tgz#365417dede44430d1c11af61027facf074bdfc53"
Expand Down Expand Up @@ -591,3 +598,8 @@ wrap-ansi@^8.0.1:
ansi-styles "^6.1.0"
string-width "^5.0.1"
strip-ansi "^7.0.1"

yocto-queue@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-1.0.0.tgz#7f816433fb2cbc511ec8bf7d263c3b58a1a3c251"
integrity sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==

0 comments on commit da68f1e

Please sign in to comment.