From a6fee2946a43668e6208d7da372579f0501c30f5 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Mon, 4 Jul 2022 17:19:19 +0200 Subject: [PATCH] feat(async-each): concurrency `0` means no limit It's identical to `Infinity` but has broader support (e.g. in JSON). --- @vates/async-each/.USAGE.md | 2 +- @vates/async-each/README.md | 2 +- @vates/async-each/index.js | 3 +++ CHANGELOG.unreleased.md | 1 + 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/@vates/async-each/.USAGE.md b/@vates/async-each/.USAGE.md index 8dabffc45..323ccabec 100644 --- a/@vates/async-each/.USAGE.md +++ b/@vates/async-each/.USAGE.md @@ -14,7 +14,7 @@ Returns a promise wich rejects as soon as a call to `iteratee` throws or a promi `opts` is an object that can contains the following options: -- `concurrency`: a number which indicates the maximum number of parallel call to `iteratee`, defaults to `1` +- `concurrency`: a number which indicates the maximum number of parallel call to `iteratee`, defaults to `1`. The value `0` means no concurrency limit. - `signal`: an abort signal to stop the iteration - `stopOnError`: wether to stop iteration of first error, or wait for all calls to finish and throw an `AggregateError`, defaults to `true` diff --git a/@vates/async-each/README.md b/@vates/async-each/README.md index 7b56ab151..2ad81ec86 100644 --- a/@vates/async-each/README.md +++ b/@vates/async-each/README.md @@ -32,7 +32,7 @@ Returns a promise wich rejects as soon as a call to `iteratee` throws or a promi `opts` is an object that can contains the following options: -- `concurrency`: a number which indicates the maximum number of parallel call to `iteratee`, defaults to `1` +- `concurrency`: a number which indicates the maximum number of parallel call to `iteratee`, defaults to `1`. The value `0` means no concurrency limit. - `signal`: an abort signal to stop the iteration - `stopOnError`: wether to stop iteration of first error, or wait for all calls to finish and throw an `AggregateError`, defaults to `true` diff --git a/@vates/async-each/index.js b/@vates/async-each/index.js index c95af2d8e..61ff415be 100644 --- a/@vates/async-each/index.js +++ b/@vates/async-each/index.js @@ -10,6 +10,9 @@ class AggregateError extends Error { } exports.asyncEach = function asyncEach(iterable, iteratee, { concurrency = 1, signal, stopOnError = true } = {}) { + if (concurrency === 0) { + concurrency = Infinity + } return new Promise((resolve, reject) => { const it = (iterable[Symbol.iterator] || iterable[Symbol.asyncIterator]).call(iterable) const errors = [] diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index ff06bf794..0369c9bf1 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -29,6 +29,7 @@ +- @vates/async-each minor - xo-web minor