Skip to content

Commit

Permalink
Add support to max network concurrent requests
Browse files Browse the repository at this point in the history
  • Loading branch information
albertfdp committed Dec 2, 2016
1 parent 1ea09c2 commit 7ae0a49
Show file tree
Hide file tree
Showing 3 changed files with 10 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('--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,
concurrency: commander.concurrency,
commandName,
}).then(() => {
const exit = () => {
Expand Down
2 changes: 2 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,
concurrency?: number,

// Loosely compare semver for invalid cases like "0.01.0"
looseSemver?: ?boolean,
Expand Down Expand Up @@ -202,6 +203,7 @@ 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') || ''),
concurrency: Number(opts.concurrency || this.getOption('concurrency') || constants.NETWORK_CONCURRENCY),
});
}

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,
concurrency?: 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,
concurrency?: 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.concurrency != null) {
this.max = opts.concurrency;
}

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 7ae0a49

Please sign in to comment.