@acala-network/chopsticks 0.3.7 → 0.3.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.
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HeadState = exports.randomId = void 0;
4
+ const rxjs_1 = require("rxjs");
4
5
  const util_1 = require("@polkadot/util");
5
6
  const logger_1 = require("../logger");
6
7
  const randomId = () => Math.random().toString(36).substring(2);
@@ -46,23 +47,27 @@ class HeadState {
46
47
  async setHead(head) {
47
48
  this.#head = head;
48
49
  for (const cb of Object.values(this.#headListeners)) {
49
- try {
50
- cb(head);
51
- }
52
- catch (error) {
53
- logger.error(error, 'callback');
54
- }
55
- }
56
- const diff = await this.#head.storageDiff();
57
- for (const [keys, cb] of Object.values(this.#storageListeners)) {
58
- const changed = keys.filter((key) => diff[key]).map((key) => [key, diff[key]]);
59
- if (changed.length > 0) {
50
+ rxjs_1.asapScheduler.schedule(() => {
60
51
  try {
61
- cb(head, changed);
52
+ cb(head);
62
53
  }
63
54
  catch (error) {
64
55
  logger.error(error, 'callback');
65
56
  }
57
+ });
58
+ }
59
+ const diff = await this.#head.storageDiff();
60
+ for (const [keys, cb] of Object.values(this.#storageListeners)) {
61
+ const changed = keys.filter((key) => diff[key]).map((key) => [key, diff[key]]);
62
+ if (changed.length > 0) {
63
+ rxjs_1.asapScheduler.schedule(() => {
64
+ try {
65
+ cb(head, changed);
66
+ }
67
+ catch (error) {
68
+ logger.error(error, 'callback');
69
+ }
70
+ });
66
71
  }
67
72
  }
68
73
  Object.assign(this.#oldValues, diff);
@@ -54,12 +54,7 @@ class TxPool {
54
54
  async upcomingBlock(count = 1) {
55
55
  if (count < 1)
56
56
  throw new Error('count needs to be greater than 0');
57
- return new Promise((resolve) => {
58
- const sub = this.#upcoming.pipe((0, operators_1.skip)(count - 1)).subscribe((block) => {
59
- sub.unsubscribe();
60
- resolve(block);
61
- });
62
- });
57
+ return (0, rxjs_1.firstValueFrom)(this.#upcoming.pipe((0, operators_1.skip)(count - 1), (0, operators_1.first)()));
63
58
  }
64
59
  async #buildBlock(wait, params) {
65
60
  await this.#chain.api.isReady;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acala-network/chopsticks",
3
- "version": "0.3.7",
3
+ "version": "0.3.8",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Bryan Chen <xlchen1291@gmail.com>",