triangle-utils 1.4.5 → 1.4.7

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.
@@ -10,25 +10,22 @@ export class UtilsBee {
10
10
  if (this.bee === undefined) {
11
11
  return undefined;
12
12
  }
13
- for (let i = 0; i < 3; i++) {
14
- try {
15
- const response = await this.bee.htmlApi({
16
- url: url,
17
- params: params
18
- });
19
- if (response.data instanceof Buffer) {
20
- return response.data;
21
- }
22
- return undefined;
13
+ try {
14
+ const response = await this.bee.htmlApi({
15
+ url: url,
16
+ params: params
17
+ });
18
+ if (response.data instanceof Buffer) {
19
+ return response.data;
23
20
  }
24
- catch (error) {
25
- if (error instanceof Error) {
26
- console.log(error.stack);
27
- }
28
- console.log("Failed to get from Scraping Bee.");
21
+ return undefined;
22
+ }
23
+ catch (error) {
24
+ if (error instanceof Error) {
25
+ console.log(error.stack);
29
26
  }
27
+ console.log("Failed to get from Scraping Bee.");
30
28
  }
31
- console.log("Failed to get from Scraping Bee, quitting.");
32
29
  return undefined;
33
30
  }
34
31
  async get(url, params = {}) {
@@ -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) => Promise<any>, concurrency?: number, print_indices?: boolean): Promise<void>;
14
+ iterate<T>(inputs: T[], f: (input: T, index: number) => Promise<any>, num_iterators?: number, print_indices?: 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,17 @@ export class UtilsMisc {
58
58
  }
59
59
  }
60
60
  }
61
- async iterate(inputs, f, concurrency = 1, print_indices = false) {
61
+ async iterate(inputs, f, num_iterators = 1, print_indices = false) {
62
62
  let index = 0;
63
63
  let iterators = [];
64
- for (let i = 0; i < concurrency; i++) {
64
+ for (let i = 0; i < num_iterators; i++) {
65
65
  iterators.push((async () => {
66
66
  while (index < inputs.length) {
67
67
  index += 1;
68
68
  if (print_indices) {
69
69
  console.log(i + ":" + (index - 1) + "/" + inputs.length);
70
70
  }
71
- await this.safe_run(() => f(inputs[index - 1]));
71
+ await this.safe_run(() => f(inputs[index - 1], index));
72
72
  }
73
73
  })());
74
74
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.5",
3
+ "version": "1.4.7",
4
4
  "main": "dist/src/index.js",
5
5
  "directories": {
6
6
  "test": "vitest"
package/src/UtilsBee.ts CHANGED
@@ -14,24 +14,21 @@ export class UtilsBee {
14
14
  if (this.bee === undefined) {
15
15
  return undefined
16
16
  }
17
- for (let i = 0; i < 3; i++) {
18
- try {
19
- const response = await this.bee.htmlApi({
20
- url : url,
21
- params : params
22
- })
23
- if (response.data instanceof Buffer) {
24
- return response.data
25
- }
26
- return undefined
27
- } catch (error) {
28
- if (error instanceof Error) {
29
- console.log(error.stack)
30
- }
31
- console.log("Failed to get from Scraping Bee.")
17
+ try {
18
+ const response = await this.bee.htmlApi({
19
+ url : url,
20
+ params : params
21
+ })
22
+ if (response.data instanceof Buffer) {
23
+ return response.data
24
+ }
25
+ return undefined
26
+ } catch (error) {
27
+ if (error instanceof Error) {
28
+ console.log(error.stack)
32
29
  }
30
+ console.log("Failed to get from Scraping Bee.")
33
31
  }
34
- console.log("Failed to get from Scraping Bee, quitting.")
35
32
  return undefined
36
33
 
37
34
  }
package/src/UtilsMisc.ts CHANGED
@@ -69,17 +69,17 @@ export class UtilsMisc {
69
69
  }
70
70
  }
71
71
 
72
- async iterate<T>(inputs : T[], f : (input : T) => Promise<any>, concurrency : number = 1, print_indices : boolean = false) {
72
+ async iterate<T>(inputs : T[], f : (input : T, index : number) => Promise<any>, num_iterators : number = 1, print_indices : boolean = false) {
73
73
  let index = 0
74
74
  let iterators = []
75
- for (let i = 0; i < concurrency; i++) {
75
+ for (let i = 0; i < num_iterators; i++) {
76
76
  iterators.push((async () => {
77
77
  while (index < inputs.length) {
78
78
  index += 1
79
79
  if (print_indices) {
80
80
  console.log(i + ":" + (index - 1) + "/" + inputs.length)
81
81
  }
82
- await this.safe_run(() => f(inputs[index - 1]))
82
+ await this.safe_run(() => f(inputs[index - 1], index))
83
83
  }
84
84
  })())
85
85
  }