it-parallel-batch
Advanced tools
Comparing version
/** | ||
* @packageDocumentation | ||
* | ||
* Takes an async iterator that emits promise-returning functions, invokes them in parallel and emits the results in the same order as the input. | ||
* | ||
* The final batch may be smaller than the batch size. | ||
* | ||
* @example | ||
* | ||
* ```javascript | ||
* import parallelBatch from 'it-parallel-batch' | ||
* import all from 'it-all' | ||
* import delay from 'delay' | ||
* | ||
* // This can also be an iterator, async iterator, generator, etc | ||
* const input = [ | ||
* async () => { | ||
* await delay(500) | ||
* | ||
* return 1 | ||
* }, | ||
* async () => { | ||
* await delay(200) | ||
* | ||
* return 2 | ||
* }, | ||
* async () => { | ||
* await delay(100) | ||
* | ||
* return 3 | ||
* } | ||
* ] | ||
* | ||
* const batchSize = 2 | ||
* | ||
* const result = await all(parallelBatch(input, batchSize)) | ||
* | ||
* console.info(result) // [1, 2, 3] | ||
* ``` | ||
*/ | ||
/** | ||
* Takes an (async) iterator that emits promise-returning functions, | ||
@@ -3,0 +43,0 @@ * invokes them in parallel and emits the results as they become available but |
@@ -0,1 +1,41 @@ | ||
/** | ||
* @packageDocumentation | ||
* | ||
* Takes an async iterator that emits promise-returning functions, invokes them in parallel and emits the results in the same order as the input. | ||
* | ||
* The final batch may be smaller than the batch size. | ||
* | ||
* @example | ||
* | ||
* ```javascript | ||
* import parallelBatch from 'it-parallel-batch' | ||
* import all from 'it-all' | ||
* import delay from 'delay' | ||
* | ||
* // This can also be an iterator, async iterator, generator, etc | ||
* const input = [ | ||
* async () => { | ||
* await delay(500) | ||
* | ||
* return 1 | ||
* }, | ||
* async () => { | ||
* await delay(200) | ||
* | ||
* return 2 | ||
* }, | ||
* async () => { | ||
* await delay(100) | ||
* | ||
* return 3 | ||
* } | ||
* ] | ||
* | ||
* const batchSize = 2 | ||
* | ||
* const result = await all(parallelBatch(input, batchSize)) | ||
* | ||
* console.info(result) // [1, 2, 3] | ||
* ``` | ||
*/ | ||
import batch from 'it-batch'; | ||
@@ -2,0 +42,0 @@ /** |
{ | ||
"name": "it-parallel-batch", | ||
"version": "3.0.3", | ||
"description": "Takes an async iterator that emits promise-returning functions, invokes them in parallel and emits the results in the same order as the input", | ||
"version": "3.0.4", | ||
"description": "Process (async)iterable values as functions with concurrency control", | ||
"author": "Alex Potsides <alex@achingbrain.net>", | ||
@@ -32,2 +32,3 @@ "license": "Apache-2.0 OR MIT", | ||
"parserOptions": { | ||
"project": true, | ||
"sourceType": "module" | ||
@@ -138,3 +139,3 @@ } | ||
"devDependencies": { | ||
"aegir": "^40.0.11", | ||
"aegir": "^41.1.9", | ||
"delay": "^6.0.0", | ||
@@ -141,0 +142,0 @@ "it-all": "^3.0.0" |
@@ -1,33 +0,13 @@ | ||
# it-parallel-batch <!-- omit in toc --> | ||
[](https://codecov.io/gh/achingbrain/it) | ||
[](https://github.com/achingbrain/it/actions/workflows/js-test-and-release.yml?query=branch%3Amaster) | ||
> Takes an async iterator that emits promise-returning functions, invokes them in parallel and emits the results in the same order as the input | ||
> Process (async)iterable values as functions with concurrency control | ||
## Table of contents <!-- omit in toc --> | ||
# About | ||
- [Install](#install) | ||
- [Browser `<script>` tag](#browser-script-tag) | ||
- [Usage](#usage) | ||
- [License](#license) | ||
- [Contribution](#contribution) | ||
Takes an async iterator that emits promise-returning functions, invokes them in parallel and emits the results in the same order as the input. | ||
## Install | ||
```console | ||
$ npm i it-parallel-batch | ||
``` | ||
### Browser `<script>` tag | ||
Loading this module through a script tag will make it's exports available as `ItParallelBatch` in the global namespace. | ||
```html | ||
<script src="https://unpkg.com/it-parallel-batch/dist/index.min.js"></script> | ||
``` | ||
The final batch may be smaller than the batch size. | ||
## Usage | ||
## Example | ||
@@ -65,4 +45,18 @@ ```javascript | ||
## License | ||
# Install | ||
```console | ||
$ npm i it-parallel-batch | ||
``` | ||
## Browser `<script>` tag | ||
Loading this module through a script tag will make it's exports available as `ItParallelBatch` in the global namespace. | ||
```html | ||
<script src="https://unpkg.com/it-parallel-batch/dist/index.min.js"></script> | ||
``` | ||
# License | ||
Licensed under either of | ||
@@ -73,4 +67,4 @@ | ||
## Contribution | ||
# Contribution | ||
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. |
@@ -0,1 +1,42 @@ | ||
/** | ||
* @packageDocumentation | ||
* | ||
* Takes an async iterator that emits promise-returning functions, invokes them in parallel and emits the results in the same order as the input. | ||
* | ||
* The final batch may be smaller than the batch size. | ||
* | ||
* @example | ||
* | ||
* ```javascript | ||
* import parallelBatch from 'it-parallel-batch' | ||
* import all from 'it-all' | ||
* import delay from 'delay' | ||
* | ||
* // This can also be an iterator, async iterator, generator, etc | ||
* const input = [ | ||
* async () => { | ||
* await delay(500) | ||
* | ||
* return 1 | ||
* }, | ||
* async () => { | ||
* await delay(200) | ||
* | ||
* return 2 | ||
* }, | ||
* async () => { | ||
* await delay(100) | ||
* | ||
* return 3 | ||
* } | ||
* ] | ||
* | ||
* const batchSize = 2 | ||
* | ||
* const result = await all(parallelBatch(input, batchSize)) | ||
* | ||
* console.info(result) // [1, 2, 3] | ||
* ``` | ||
*/ | ||
import batch from 'it-batch' | ||
@@ -2,0 +43,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
12832
22.52%185
184.62%69
-8%