update
This commit is contained in:
+3
-1
@@ -3,6 +3,8 @@ declare namespace pMap {
|
||||
/**
|
||||
Number of concurrently pending promises returned by `mapper`.
|
||||
|
||||
Must be an integer from 1 and up or `Infinity`.
|
||||
|
||||
@default Infinity
|
||||
*/
|
||||
readonly concurrency?: number;
|
||||
@@ -21,7 +23,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>;
|
||||
|
||||
+6
-6
@@ -14,11 +14,11 @@ module.exports = async (
|
||||
throw new TypeError('Mapper function is required');
|
||||
}
|
||||
|
||||
if (!(typeof concurrency === 'number' && concurrency >= 1)) {
|
||||
throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${concurrency}\` (${typeof concurrency})`);
|
||||
if (!((Number.isSafeInteger(concurrency) || concurrency === Infinity) && concurrency >= 1)) {
|
||||
throw new TypeError(`Expected \`concurrency\` to be an integer from 1 and up or \`Infinity\`, 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) {
|
||||
|
||||
+1
-1
@@ -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:
|
||||
|
||||
|
||||
+17
-16
@@ -1,36 +1,36 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"p-map@3.0.0",
|
||||
"/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series"
|
||||
"p-map@4.0.0",
|
||||
"/home/node/nuxt"
|
||||
]
|
||||
],
|
||||
"_from": "p-map@3.0.0",
|
||||
"_id": "p-map@3.0.0",
|
||||
"_from": "p-map@4.0.0",
|
||||
"_id": "p-map@4.0.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-d3qXVTF/s+W+CdJ5A29wywV2n8CQQYahlgz2bFiA+4eVNJbHJodPZ+/gXwPGh0bOqA+j8S+6+ckmvLGPk1QpxQ==",
|
||||
"_integrity": "sha512-/bjOqmgETBYB5BoEeGVea8dmvHb2m9GLy1E9W43yeyfP6QQCZGFNa+XRceJEuDB6zqr+gKpIAmlLebMpykw/MQ==",
|
||||
"_location": "/p-map",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "p-map@3.0.0",
|
||||
"raw": "p-map@4.0.0",
|
||||
"name": "p-map",
|
||||
"escapedName": "p-map",
|
||||
"rawSpec": "3.0.0",
|
||||
"rawSpec": "4.0.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "3.0.0"
|
||||
"fetchSpec": "4.0.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/cacache"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/p-map/-/p-map-3.0.0.tgz",
|
||||
"_spec": "3.0.0",
|
||||
"_where": "/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series",
|
||||
"_resolved": "https://registry.npmjs.org/p-map/-/p-map-4.0.0.tgz",
|
||||
"_spec": "4.0.0",
|
||||
"_where": "/home/node/nuxt",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
"url": "https://sindresorhus.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/sindresorhus/p-map/issues"
|
||||
@@ -45,16 +45,17 @@
|
||||
"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"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
"node": ">=10"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"funding": "https://github.com/sponsors/sindresorhus",
|
||||
"homepage": "https://github.com/sindresorhus/p-map#readme",
|
||||
"keywords": [
|
||||
"promise",
|
||||
@@ -83,5 +84,5 @@
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd"
|
||||
},
|
||||
"version": "3.0.0"
|
||||
"version": "4.0.0"
|
||||
}
|
||||
|
||||
+8
-18
@@ -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,19 +59,24 @@ Type: `object`
|
||||
|
||||
##### concurrency
|
||||
|
||||
Type: `number`<br>
|
||||
Default: `Infinity`<br>
|
||||
Type: `number` (Integer)\
|
||||
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
|
||||
|
||||
@@ -84,16 +87,3 @@ When set to `false`, instead of stopping when a promise rejects, it will wait fo
|
||||
- [p-map-series](https://github.com/sindresorhus/p-map-series) - Map over promises serially
|
||||
- [p-queue](https://github.com/sindresorhus/p-queue) - Promise queue with concurrency control
|
||||
- [More…](https://github.com/sindresorhus/promise-fun)
|
||||
|
||||
|
||||
---
|
||||
|
||||
<div align="center">
|
||||
<b>
|
||||
<a href="https://tidelift.com/subscription/pkg/npm-p-map?utm_source=npm-p-map&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
||||
</b>
|
||||
<br>
|
||||
<sub>
|
||||
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
||||
</sub>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user