Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement promises library with non-blocking methods #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tmalahie
Copy link
Contributor

@tmalahie tmalahie commented Dec 7, 2024

This PR adds an alternate version of the wrapper library that supports async operations.
The issue with the current wrapper is that each method is blocking, which is generally an anti-pattern in JS. Concretely it means that when you call a method that takes multiple seconds to complete (like refreshing your assetsà, the whole app will freeze for multiple seconds and you can't do any other operation in between.
I added another module rgb-lib/promises where all methods perform the tasks asynchronously instead and return a promise. It uses worker threads under the hood.

Usage:

const { Wallet, restoreKeys } = require("rgb-lib/promises");
const { WalletData, BitcoinNetwork } = require("rgb-lib");

async function main() {
  const { accountXpub } = await restoreKeys(BitcoinNetwork.Testnet, mnemonic);

  const wallet = await Wallet(new WalletData({
    pubkey: accountXpub,
    // ...
  }));

  const online = await wallet.goOnline(true, "ssl://electrum.iriswallet.com:50013");
  const balance = await wallet.getBtcBalance(online, true);
  
  // etc
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant