Skip to content

Commit

Permalink
Use p-map
Browse files Browse the repository at this point in the history
  • Loading branch information
shannonrothe committed Mar 8, 2021
1 parent d011028 commit 4e46112
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
Binary file added .DS_Store
Binary file not shown.
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"html.format.enable": false,
"json.format.enable": false,
"javascript.format.enable": false,
"editor.codeActionsOnSave": null
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
"lodash.template": "^4.5.0",
"log-symbols": "^4.0.0",
"make-dir": "^3.1.0",
"p-all": "^3.0.0",
"p-memoize": "^4.0.1",
"plur": "^4.0.0",
"unused-filename": "^2.1.0",
Expand Down
17 changes: 10 additions & 7 deletions source/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {promisify} from 'util';
import {parse as parseUrl} from 'url'; // eslint-disable-line node/no-deprecated-api
import {promisify} from 'util';
import path = require('path');
import fs = require('fs');
import {EventEmitter} from 'events';
Expand All @@ -17,7 +17,7 @@ import viewportList = require('viewport-list');
import template = require('lodash.template');
import plur = require('plur');
import filenamifyUrl = require('filenamify-url');
import pAll = require('p-all');
import pMap = require('p-map');
import os = require('os');

// TODO: Move this to `type-fest`
Expand Down Expand Up @@ -171,11 +171,14 @@ export default class Pageres extends EventEmitter {
return this.viewport({url: source.url, sizes, keywords}, options);
}

const screenshots: Screenshot[] = await pAll(this.sizes.map(async (size: string): Promise<Screenshot> => {
return this.create(source.url, size, options);
}), {concurrency: cpuCount * 2});

this.items.push(...screenshots);
await pMap(
this.sizes,
async (size: string) => {
this.sizes.push(size);
this.items.push(await this.create(source.url, size, options));
},
{concurrency: cpuCount * 2}
);

return undefined;
}));
Expand Down

0 comments on commit 4e46112

Please sign in to comment.