Skip to content

Commit

Permalink
Add support to max network concurrent requests (yarnpkg#2129)
Browse files Browse the repository at this point in the history
  • Loading branch information
albertfdp committed Jan 3, 2017
1 parent c088db0 commit 0d75a22
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ commander.option(
'--no-progress',
'disable progress bar',
);
commander.option('--network-concurrency <number>', 'maximum number of concurrent network requests');

// get command name
let commandName: ?string = args.shift() || '';
Expand Down Expand Up @@ -360,6 +361,7 @@ config.init({
production: commander.production,
httpProxy: commander.proxy,
httpsProxy: commander.httpsProxy,
networkConcurrency: commander.networkConcurrency,
commandName,
}).then(() => {
const exit = () => {
Expand Down
3 changes: 3 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export type ConfigOptions = {
cafile?: ?string,
production?: boolean,
binLinks?: boolean,
networkConcurrency?: number,

// Loosely compare semver for invalid cases like "0.01.0"
looseSemver?: ?boolean,
Expand Down Expand Up @@ -199,6 +200,8 @@ export default class Config {
cafile: String(opts.cafile || this.getOption('cafile') || ''),
cert: String(opts.cert || this.getOption('cert') || ''),
key: String(opts.key || this.getOption('key') || ''),
networkConcurrency: Number(opts.networkConcurrency || this.getOption('network-concurrency') ||
constants.NETWORK_CONCURRENCY),
});

//init & create cacheFolder, tempFolder
Expand Down
6 changes: 6 additions & 0 deletions src/util/request-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type RequestParams<T> = {
encoding?: ?string,
ca?: Array<string>,
cert?: string,
networkConcurrency?: number,
key?: string,
forever?: boolean,
strictSSL?: boolean,
Expand Down Expand Up @@ -114,6 +115,7 @@ export default class RequestManager {
ca?: Array<string>,
cafile?: string,
cert?: string,
networkConcurrency?: number,
key?: string,
}) {
if (opts.userAgent != null) {
Expand Down Expand Up @@ -144,6 +146,10 @@ export default class RequestManager {
this.ca = opts.ca;
}

if (opts.networkConcurrency != null) {
this.max = opts.networkConcurrency;
}

if (opts.cafile != null && opts.cafile != '') {
// The CA bundle file can contain one or more certificates with comments/text between each PEM block.
// tls.connect wants an array of certificates without any comments/text, so we need to split the string
Expand Down

0 comments on commit 0d75a22

Please sign in to comment.