Skip to content

Commit 4cefa01

Browse files
committed
feat: concurrent option
1 parent b57946c commit 4cefa01

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

src/download.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ export default async function (
55
repos: GithubRepo[],
66
user: GithubUser,
77
token: string,
8-
path: string
8+
path: string,
9+
concurrent: number
910
) {
1011
const total = repos.length;
1112
let done = 0;
1213
let failed = 0;
13-
const maxConcurrentClones = 10;
1414

1515
const clonePromises: any[] = [];
1616

@@ -28,8 +28,8 @@ export default async function (
2828
);
2929

3030
// Limit concurrent clones
31-
if (clonePromises.length >= maxConcurrentClones) {
32-
await Promise.all(clonePromises.splice(0, maxConcurrentClones));
31+
if (clonePromises.length >= concurrent) {
32+
await Promise.all(clonePromises.splice(0, concurrent));
3333
console.log(`Downloaded ${done}/${total} , Failed ${failed}`);
3434
}
3535
}

src/index.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ program
2828
"(optional) output directory; default is current directory",
2929
""
3030
)
31+
.option(
32+
"-c, --concurrent <char>",
33+
"(optional) concurrent/parallel downloads; default is 2",
34+
""
35+
)
3136
.option(
3237
"-u, --utc",
3338
"(optional) whether your utc timezone; default is system",
@@ -47,6 +52,9 @@ program
4752
process.exit();
4853
}
4954

55+
// --- get concurrent/parallel count
56+
const concurrent = Number(data.concurrent);
57+
5058
// --- name of the file
5159
console.log(info, "processing filename & output path");
5260
let name = fileName(data.name, data.utc);
@@ -69,8 +77,11 @@ program
6977
console.log(success, "fetched list of all user repos");
7078

7179
// --- download all repos
72-
console.log(info, "downloading repos");
73-
await download(repos, user, data.token, path);
80+
console.log(
81+
info,
82+
`downloading repos - ${concurrent} repos in parallel`
83+
);
84+
await download(repos, user, data.token, path, concurrent);
7485
console.log(success, "downloaded all repos");
7586

7687
// --- if compress

0 commit comments

Comments
 (0)