This is not GitHub.com

Like what you see? Install OctoLinker now!

Skip to content
Permalink
Browse files

Require Node.js 10

  • Loading branch information
sindresorhus committed Mar 5, 2020
1 parent f8ccb4e commit bf037695761aa3c8a54ef4efffdadff0d4cb0cd9
Showing with 18 additions and 22 deletions.
  1. +0 −1 .travis.yml
  2. +1 −1 index.d.ts
  3. +4 −4 index.js
  4. +4 −4 index.test-d.ts
  5. +1 −1 license
  6. +5 −4 package.json
  7. +3 −7 readme.md
@@ -2,4 +2,3 @@ language: node_js
node_js:
- '12'
- '10'
- '8'
@@ -21,7 +21,7 @@ declare namespace pMap {
@param element - Iterated element.
@param index - Index of the element in the source array.
*/
type Mapper<Element = any, NewElement = any> = (
type Mapper<Element = any, NewElement = unknown> = (
element: Element,
index: number
) => NewElement | Promise<NewElement>;
@@ -18,7 +18,7 @@ module.exports = async (
throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${concurrency}\` (${typeof concurrency})`);
}

const ret = [];
const result = [];
const errors = [];
const iterator = iterable[Symbol.iterator]();
let isRejected = false;
@@ -32,7 +32,7 @@ module.exports = async (
}

const nextItem = iterator.next();
const i = currentIndex;
const index = currentIndex;
currentIndex++;

if (nextItem.done) {
@@ -42,7 +42,7 @@ module.exports = async (
if (!stopOnError && errors.length !== 0) {
reject(new AggregateError(errors));
} else {
resolve(ret);
resolve(result);
}
}

@@ -54,7 +54,7 @@ module.exports = async (
(async () => {
try {
const element = await nextItem.value;
ret[i] = await mapper(element, i);
result[index] = await mapper(element, index);
resolvingCount--;
next();
} catch (error) {
@@ -14,10 +14,10 @@ const numbers = [
2
];

const asyncMapper = async (site: string) => site;
const asyncSyncMapper = (site: string, index: number) =>
const asyncMapper = async (site: string): Promise<string> => site;
const asyncSyncMapper = async (site: string, index: number): Promise<string> =>
index > 1 ? site : Promise.resolve(site);
const multiResultTypeMapper = (site: string, index: number) =>
const multiResultTypeMapper = async (site: string, index: number): Promise<string | number> =>
index > 1 ? site.length : site;

expectType<Mapper>(asyncMapper);
@@ -35,7 +35,7 @@ expectType<Promise<string[]>>(pMap(sites, asyncMapper));
expectType<Promise<string[]>>(pMap(sites, asyncMapper, {concurrency: 2}));

expectType<Promise<string[]>>(pMap(sites, asyncSyncMapper));
expectType<Promise<(string | number)[]>>(pMap(sites, multiResultTypeMapper));
expectType<Promise<Array<string | number>>>(pMap(sites, multiResultTypeMapper));

expectType<Promise<string[]>>(pMap(sites, (site: string) => site));
expectType<Promise<number[]>>(pMap(sites, (site: string) => site.length));
@@ -1,6 +1,6 @@
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

@@ -4,13 +4,14 @@
"description": "Map over promises concurrently",
"license": "MIT",
"repository": "sindresorhus/p-map",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"engines": {
"node": ">=8"
"node": ">=10"
},
"scripts": {
"test": "xo && ava && tsd"
@@ -46,7 +47,7 @@
"in-range": "^2.0.0",
"random-int": "^2.0.0",
"time-span": "^3.1.0",
"tsd": "^0.7.2",
"xo": "^0.24.0"
"tsd": "^0.7.4",
"xo": "^0.27.2"
}
}
@@ -4,14 +4,12 @@
Useful when you need to run promise-returning & async functions multiple times with different inputs concurrently.


## Install

```
$ npm install p-map
```


## Usage

```js
@@ -61,27 +59,25 @@ Type: `object`

##### concurrency

Type: `number`<br>
Default: `Infinity`<br>
Type: `number`\
Default: `Infinity`\
Minimum: `1`

Number of concurrently pending promises returned by `mapper`.

##### stopOnError

Type: `boolean`<br>
Type: `boolean`\
Default: `true`

When set to `false`, instead of stopping when a promise rejects, it will wait for all the promises to settle and then reject with an [aggregated error](https://github.com/sindresorhus/aggregate-error) containing all the errors from the rejected promises.


## p-map for enterprise

Available as part of the Tidelift Subscription.

The maintainers of p-map and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-p-map?utm_source=npm-p-map&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)


## Related

- [p-all](https://github.com/sindresorhus/p-all) - Run promise-returning & async functions concurrently with optional limited concurrency

0 comments on commit bf03769

Please sign in to comment.
You can’t perform that action at this time.