@clipboard-health/util-ts 4.6.77 → 4.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@clipboard-health/util-ts",
3
3
  "description": "TypeScript utilities.",
4
- "version": "4.6.77",
4
+ "version": "4.7.0",
5
5
  "bugs": "https://github.com/ClipboardHealth/core-utils/issues",
6
6
  "dependencies": {
7
7
  "tslib": "2.8.1"
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Iterates over an array and applies an async function to each item sequentially.
3
+ *
4
+ * Usages of this function should be intentional. If it's possible to parallelize the tasks, you
5
+ * should use `.map` and `Promise.all()` instead, or you could batch promises together with some
6
+ * limit. Only uses this when order matters or when parallel execution would cause issues (e.g.,
7
+ * rate limiting, database transactions).
8
+ *
9
+ *
10
+ * @param array - The array to iterate over.
11
+ * @param asyncTask - The async function to apply to each item.
12
+ * @example
13
+ * const users = [{ id: 1 }, { id: 2 }, { id: 3 }];
14
+ * await forEachAsyncSequentially(users, async (user) => {
15
+ * await sendEmail(user.id);
16
+ * });
17
+ */
18
+ export declare function forEachAsyncSequentially<T>(array: T[], asyncTask: (item: T, index: number) => Promise<unknown>): Promise<void>;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.forEachAsyncSequentially = forEachAsyncSequentially;
4
+ /**
5
+ * Iterates over an array and applies an async function to each item sequentially.
6
+ *
7
+ * Usages of this function should be intentional. If it's possible to parallelize the tasks, you
8
+ * should use `.map` and `Promise.all()` instead, or you could batch promises together with some
9
+ * limit. Only uses this when order matters or when parallel execution would cause issues (e.g.,
10
+ * rate limiting, database transactions).
11
+ *
12
+ *
13
+ * @param array - The array to iterate over.
14
+ * @param asyncTask - The async function to apply to each item.
15
+ * @example
16
+ * const users = [{ id: 1 }, { id: 2 }, { id: 3 }];
17
+ * await forEachAsyncSequentially(users, async (user) => {
18
+ * await sendEmail(user.id);
19
+ * });
20
+ */
21
+ async function forEachAsyncSequentially(array, asyncTask) {
22
+ for (const [index, item] of array.entries()) {
23
+ // eslint-disable-next-line no-await-in-loop
24
+ await asyncTask(item, index);
25
+ }
26
+ }
27
+ //# sourceMappingURL=forEachAsyncSequentially.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forEachAsyncSequentially.js","sourceRoot":"","sources":["../../../../../../packages/util-ts/src/lib/arrays/forEachAsyncSequentially.ts"],"names":[],"mappings":";;AAiBA,4DAQC;AAzBD;;;;;;;;;;;;;;;;GAgBG;AACI,KAAK,UAAU,wBAAwB,CAC5C,KAAU,EACV,SAAuD;IAEvD,KAAK,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;QAC5C,4CAA4C;QAC5C,MAAM,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC/B,CAAC;AACH,CAAC"}
@@ -1,3 +1,4 @@
1
1
  export * from "./chunk";
2
+ export * from "./forEachAsyncSequentially";
2
3
  export * from "./head";
3
4
  export * from "./nonEmptyArray";
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./chunk"), exports);
5
+ tslib_1.__exportStar(require("./forEachAsyncSequentially"), exports);
5
6
  tslib_1.__exportStar(require("./head"), exports);
6
7
  tslib_1.__exportStar(require("./nonEmptyArray"), exports);
7
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/util-ts/src/lib/arrays/index.ts"],"names":[],"mappings":";;;AAAA,kDAAwB;AACxB,iDAAuB;AACvB,0DAAgC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/util-ts/src/lib/arrays/index.ts"],"names":[],"mappings":";;;AAAA,kDAAwB;AACxB,qEAA2C;AAC3C,iDAAuB;AACvB,0DAAgC"}