@nu-art/ts-common 0.201.24 → 0.201.26

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@nu-art/ts-common",
3
- "version": "0.201.24",
3
+ "version": "0.201.26",
4
4
  "description": "js and ts infra",
5
5
  "keywords": [
6
6
  "TacB0sS",
@@ -75,6 +75,25 @@ export declare function sortArray<T>(array: T[], map?: keyof T | (keyof T)[] | (
75
75
  * "splits" array into given size of chunks and then does "action" on chunk and return to array of actions on chunks +-
76
76
  * */
77
77
  export declare function batchAction<T extends any = any, R extends any = any>(arr: T[], chunk: number, action: (elements: T[]) => Promise<R | R[]>): Promise<R[]>;
78
+ /**
79
+ * Processes an array of promise-returning tasks sequentially.
80
+ *
81
+ * @typeParam T - The type of resolved value of the promises.
82
+ * @returns A promise that resolves to an array of resolved values.
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * let tasks = [
87
+ * () => new Promise<number>(resolve => setTimeout(() => resolve(1), 1000)),
88
+ * () => new Promise<number>(resolve => setTimeout(() => resolve(2), 500)),
89
+ * () => new Promise<number>(resolve => setTimeout(() => resolve(3), 1500))
90
+ * ];
91
+ *
92
+ * Promise_all_sequentially(tasks).then(console.log); // [1, 2, 3]
93
+ * ```
94
+ * @param promises
95
+ */
96
+ export declare function Promise_all_sequentially<T>(promises: Array<() => Promise<T>>): Promise<T[]>;
78
97
  export declare function batchActionParallel<T extends any = any, R extends any = any>(arr: T[], chunk: number, action: (elements: T[]) => Promise<R | R[]>): Promise<R[]>;
79
98
  /**
80
99
  * Returns a flat array from an array of arrays.
@@ -26,7 +26,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
26
26
  });
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.arrayIncludesAny = exports.firstElement = exports.lastElement = exports.asOptionalArray = exports.asArray = exports.generateArray = exports.toggleInArray = exports.groupArrayBy = exports.flatArray = exports.batchActionParallel = exports.batchAction = exports.sortArray = exports.reduceToMap = exports.arrayToMap = exports.filterFalsy = exports.filterInstances = exports.filterDuplicates = exports.findDuplicates = exports.filterAsync = exports.toggleElementInArray = exports.addItemToArrayAtIndex = exports.addItemToArray = exports.removeFromArrayByIndex = exports.removeFromArray = exports.removeItemFromArray = exports.filterInOut = void 0;
29
+ exports.arrayIncludesAny = exports.firstElement = exports.lastElement = exports.asOptionalArray = exports.asArray = exports.generateArray = exports.toggleInArray = exports.groupArrayBy = exports.flatArray = exports.batchActionParallel = exports.Promise_all_sequentially = exports.batchAction = exports.sortArray = exports.reduceToMap = exports.arrayToMap = exports.filterFalsy = exports.filterInstances = exports.filterDuplicates = exports.findDuplicates = exports.filterAsync = exports.toggleElementInArray = exports.addItemToArrayAtIndex = exports.addItemToArray = exports.removeFromArrayByIndex = exports.removeFromArray = exports.removeItemFromArray = exports.filterInOut = void 0;
30
30
  const tools_1 = require("./tools");
31
31
  const object_tools_1 = require("./object-tools");
32
32
  function filterInOut(input, filter) {
@@ -188,6 +188,34 @@ function batchAction(arr, chunk, action) {
188
188
  });
189
189
  }
190
190
  exports.batchAction = batchAction;
191
+ /**
192
+ * Processes an array of promise-returning tasks sequentially.
193
+ *
194
+ * @typeParam T - The type of resolved value of the promises.
195
+ * @returns A promise that resolves to an array of resolved values.
196
+ *
197
+ * @example
198
+ * ```typescript
199
+ * let tasks = [
200
+ * () => new Promise<number>(resolve => setTimeout(() => resolve(1), 1000)),
201
+ * () => new Promise<number>(resolve => setTimeout(() => resolve(2), 500)),
202
+ * () => new Promise<number>(resolve => setTimeout(() => resolve(3), 1500))
203
+ * ];
204
+ *
205
+ * Promise_all_sequentially(tasks).then(console.log); // [1, 2, 3]
206
+ * ```
207
+ * @param promises
208
+ */
209
+ function Promise_all_sequentially(promises) {
210
+ return __awaiter(this, void 0, void 0, function* () {
211
+ const results = [];
212
+ for (const promise of promises) {
213
+ results.push(yield promise());
214
+ }
215
+ return results;
216
+ });
217
+ }
218
+ exports.Promise_all_sequentially = Promise_all_sequentially;
191
219
  function batchActionParallel(arr, chunk, action) {
192
220
  return __awaiter(this, void 0, void 0, function* () {
193
221
  const promises = [];