@alephium/web3 2.0.7 → 2.0.8

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.
@@ -823,7 +823,8 @@ function subscribeEventsFromContract(options, address, eventIndex, decodeFunc, f
823
823
  pollingInterval: options.pollingInterval,
824
824
  messageCallback: messageCallback,
825
825
  errorCallback: errorCallback,
826
- onEventCountChanged: options.onEventCountChanged
826
+ onEventCountChanged: options.onEventCountChanged,
827
+ parallel: options.parallel
827
828
  };
828
829
  return (0, events_1.subscribeToEvents)(opt, address, fromCount);
829
830
  }
@@ -1242,7 +1243,8 @@ function subscribeContractEvents(contract, instance, options, fromCount) {
1242
1243
  pollingInterval: options.pollingInterval,
1243
1244
  messageCallback: messageCallback,
1244
1245
  errorCallback: errorCallback,
1245
- onEventCountChanged: options.onEventCountChanged
1246
+ onEventCountChanged: options.onEventCountChanged,
1247
+ parallel: options.parallel
1246
1248
  };
1247
1249
  return (0, events_1.subscribeToEvents)(opt, instance.address, fromCount);
1248
1250
  }
@@ -2,11 +2,13 @@ import { node } from '../api';
2
2
  import { Subscription, SubscribeOptions } from '../utils';
3
3
  export interface EventSubscribeOptions<Message> extends SubscribeOptions<Message> {
4
4
  onEventCountChanged?: (eventCount: number) => Promise<void> | void;
5
+ parallel?: boolean;
5
6
  }
6
7
  export declare class EventSubscription extends Subscription<node.ContractEvent> {
7
8
  readonly contractAddress: string;
8
9
  private fromCount;
9
10
  private onEventCountChanged?;
11
+ private parallel;
10
12
  constructor(options: EventSubscribeOptions<node.ContractEvent>, contractAddress: string, fromCount?: number);
11
13
  currentEventCount(): number;
12
14
  private getEvents;
@@ -46,9 +46,11 @@ const utils_1 = require("../utils");
46
46
  class EventSubscription extends utils_1.Subscription {
47
47
  constructor(options, contractAddress, fromCount) {
48
48
  super(options);
49
+ this.parallel = false;
49
50
  this.contractAddress = contractAddress;
50
51
  this.fromCount = typeof fromCount === 'undefined' ? 0 : fromCount;
51
52
  this.onEventCountChanged = options.onEventCountChanged;
53
+ this.parallel = options.parallel ?? false;
52
54
  }
53
55
  currentEventCount() {
54
56
  return this.fromCount;
@@ -72,8 +74,15 @@ class EventSubscription extends utils_1.Subscription {
72
74
  if (this.fromCount === events.nextStart) {
73
75
  return;
74
76
  }
75
- const promises = events.events.map((event) => this.messageCallback(event));
76
- await Promise.all(promises);
77
+ if (this.parallel) {
78
+ const promises = events.events.map((event) => this.messageCallback(event));
79
+ await Promise.all(promises);
80
+ }
81
+ else {
82
+ for (const event of events.events) {
83
+ await this.messageCallback(event);
84
+ }
85
+ }
77
86
  this.fromCount = events.nextStart;
78
87
  if (this.onEventCountChanged !== undefined) {
79
88
  await this.onEventCountChanged(this.fromCount);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alephium/web3",
3
- "version": "2.0.7",
3
+ "version": "2.0.8",
4
4
  "description": "A JS/TS library to interact with the Alephium platform",
5
5
  "license": "GPL",
6
6
  "main": "dist/src/index.js",
@@ -1334,7 +1334,8 @@ export function subscribeEventsFromContract<T extends Fields, M extends Contract
1334
1334
  pollingInterval: options.pollingInterval,
1335
1335
  messageCallback: messageCallback,
1336
1336
  errorCallback: errorCallback,
1337
- onEventCountChanged: options.onEventCountChanged
1337
+ onEventCountChanged: options.onEventCountChanged,
1338
+ parallel: options.parallel
1338
1339
  }
1339
1340
  return subscribeToEvents(opt, address, fromCount)
1340
1341
  }
@@ -1907,7 +1908,8 @@ export function subscribeContractEvents(
1907
1908
  pollingInterval: options.pollingInterval,
1908
1909
  messageCallback: messageCallback,
1909
1910
  errorCallback: errorCallback,
1910
- onEventCountChanged: options.onEventCountChanged
1911
+ onEventCountChanged: options.onEventCountChanged,
1912
+ parallel: options.parallel
1911
1913
  }
1912
1914
  return subscribeToEvents(opt, instance.address, fromCount)
1913
1915
  }
@@ -23,18 +23,21 @@ import { ContractEvents } from '../api/api-alephium'
23
23
 
24
24
  export interface EventSubscribeOptions<Message> extends SubscribeOptions<Message> {
25
25
  onEventCountChanged?: (eventCount: number) => Promise<void> | void
26
+ parallel?: boolean
26
27
  }
27
28
 
28
29
  export class EventSubscription extends Subscription<node.ContractEvent> {
29
30
  readonly contractAddress: string
30
31
  private fromCount: number
31
32
  private onEventCountChanged?: (eventCount: number) => Promise<void> | void
33
+ private parallel = false
32
34
 
33
35
  constructor(options: EventSubscribeOptions<node.ContractEvent>, contractAddress: string, fromCount?: number) {
34
36
  super(options)
35
37
  this.contractAddress = contractAddress
36
38
  this.fromCount = typeof fromCount === 'undefined' ? 0 : fromCount
37
39
  this.onEventCountChanged = options.onEventCountChanged
40
+ this.parallel = options.parallel ?? false
38
41
  }
39
42
 
40
43
  currentEventCount(): number {
@@ -61,8 +64,15 @@ export class EventSubscription extends Subscription<node.ContractEvent> {
61
64
  return
62
65
  }
63
66
 
64
- const promises = events.events.map((event) => this.messageCallback(event))
65
- await Promise.all(promises)
67
+ if (this.parallel) {
68
+ const promises = events.events.map((event) => this.messageCallback(event))
69
+ await Promise.all(promises)
70
+ } else {
71
+ for (const event of events.events) {
72
+ await this.messageCallback(event)
73
+ }
74
+ }
75
+
66
76
  this.fromCount = events.nextStart
67
77
 
68
78
  if (this.onEventCountChanged !== undefined) {