Skip to content

Commit

Permalink
chunkedAsync improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ogroppo committed Mar 17, 2024
1 parent 8dd25bd commit 72f1f17
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# deverything

## 0.47.1

### Patch Changes

- chunkedAsync impr

## 0.47.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "deverything",
"version": "0.47.0",
"version": "0.47.1",
"description": "Everything you need for Dev",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/chunkedAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import { chunkArray } from "./chunkArray";
export const chunkedAsync = async <T>(
array: T[],
chunkSize: number,
fn: (chunk: T[]) => Promise<any>
fn: (chunk: T[], chunkIndex: number, chunks: T[][]) => Promise<any>
): Promise<any[]> => {
const chunkResults: any[] = [];

const chunks = chunkArray(array, chunkSize);
for (const chunk of chunks) {
const chunkResult = await fn(chunk);
for (const [chunkIndex, chunk] of chunks.entries()) {
const chunkResult = await fn(chunk, chunkIndex, chunks);
chunkResults.push(chunkResult);
}

Expand Down

0 comments on commit 72f1f17

Please sign in to comment.