triangle-utils 1.4.29 → 1.4.30

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.
@@ -11,7 +11,7 @@ export declare class UtilsMisc {
11
11
  send_email(recipient: string, subject: string, text: string): Promise<boolean>;
12
12
  admin_alert(text: string): Promise<boolean>;
13
13
  safe_run(f: () => Promise<any>): Promise<void>;
14
- iterate<T>(inputs: T[], f: (input: T, iterator_id: number) => Promise<any>, num_iterators?: number, print_indices?: boolean): Promise<void>;
14
+ iterate<T>(inputs: T[], f: (input: T, iterator_id: number, index: number) => Promise<any>, num_iterators?: number, print_option?: number | boolean): Promise<void>;
15
15
  static wait(duration: number): Promise<unknown>;
16
16
  static get_current_time(): string;
17
17
  static get_current_milliseconds(): number;
@@ -58,17 +58,18 @@ export class UtilsMisc {
58
58
  }
59
59
  }
60
60
  }
61
- async iterate(inputs, f, num_iterators = 1, print_indices = false) {
61
+ async iterate(inputs, f, num_iterators = 1, print_option) {
62
+ const print_freq = typeof print_option === "boolean" ? (print_option === true ? 1 : 0) : print_option;
62
63
  let index = 0;
63
64
  let iterators = [];
64
- for (let i = 0; i < num_iterators; i++) {
65
+ for (let iterator_id = 0; iterator_id < num_iterators; iterator_id++) {
65
66
  iterators.push((async () => {
66
67
  while (index < inputs.length) {
67
68
  index += 1;
68
- if (print_indices) {
69
- console.log(i + ":" + (index - 1) + "/" + inputs.length);
69
+ if (print_freq !== undefined && (index % print_freq === 0)) {
70
+ console.log(iterator_id + ":" + (index - 1) + "/" + inputs.length);
70
71
  }
71
- await this.safe_run(() => f(inputs[index - 1], i));
72
+ await this.safe_run(() => f(inputs[index - 1], iterator_id, index));
72
73
  }
73
74
  })());
74
75
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.29",
3
+ "version": "1.4.30",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "directories": {
package/src/UtilsMisc.ts CHANGED
@@ -69,17 +69,18 @@ export class UtilsMisc {
69
69
  }
70
70
  }
71
71
 
72
- async iterate<T>(inputs : T[], f : (input : T, iterator_id : number) => Promise<any>, num_iterators : number = 1, print_indices : boolean = false) {
72
+ async iterate<T>(inputs : T[], f : (input : T, iterator_id : number, index : number) => Promise<any>, num_iterators : number = 1, print_option? : number | boolean) {
73
+ const print_freq : number | undefined = typeof print_option === "boolean" ? (print_option === true ? 1 : 0) : print_option
73
74
  let index = 0
74
75
  let iterators = []
75
- for (let i = 0; i < num_iterators; i++) {
76
+ for (let iterator_id = 0; iterator_id < num_iterators; iterator_id++) {
76
77
  iterators.push((async () => {
77
78
  while (index < inputs.length) {
78
79
  index += 1
79
- if (print_indices) {
80
- console.log(i + ":" + (index - 1) + "/" + inputs.length)
80
+ if (print_freq !== undefined && (index % print_freq === 0)) {
81
+ console.log(iterator_id + ":" + (index - 1) + "/" + inputs.length)
81
82
  }
82
- await this.safe_run(() => f(inputs[index - 1], i))
83
+ await this.safe_run(() => f(inputs[index - 1], iterator_id, index))
83
84
  }
84
85
  })())
85
86
  }