Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Limit the number of active concurrent connection
  • Loading branch information
Jacob Goh committed Nov 10, 2018
1 parent 86ff05e commit 6aaed6d
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions index.js
Expand Up @@ -7,6 +7,7 @@ const { resolve } = require('url');
const fs = require('fs');

const baseUrl = `https://imdb.com`;
const maxConcurrentReq = 10;

const allUrl$ = new BehaviorSubject(baseUrl);

Expand All @@ -20,17 +21,21 @@ const uniqueUrl$ = allUrl$.pipe(
);

const urlAndDOM$ = uniqueUrl$.pipe(
mergeMap(url => {
return from(rp(url)).pipe(
// get the cheerio function $
map(html => cheerio.load(html)),
// add URL to the result. It will be used later for crawling
map($ => ({
$,
url
}))
);
}),
mergeMap(
url => {
return from(rp(url)).pipe(
// get the cheerio function $
map(html => cheerio.load(html)),
// add URL to the result. It will be used later for crawling
map($ => ({
$,
url
}))
);
},
null,
maxConcurrentReq
),
share()
);

Expand Down

0 comments on commit 6aaed6d

Please sign in to comment.