How to use the @requestnetwork/utils.cachedThrottle function in @requestnetwork/utils

To help you get started, we’ve selected a few @requestnetwork/utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RequestNetwork / requestNetwork / packages / ethereum-storage / src / ethereum-blocks.ts View on Github external
logger?: LogTypes.ILogger,
  ) {
    this.eth = eth;

    this.firstSignificantBlockNumber = firstSignificantBlockNumber;

    this.getLastBlockNumberMinDelay = getLastBlockNumberMinDelay;

    this.logger = logger || new Utils.SimpleLogger();

    // Get retry parameter values from config
    this.retryDelay = retryDelay;
    this.maxRetries = maxRetries;

    // Setup the throttled and retriable getLastBlockNumber function
    this.getLastBlockNumber = Utils.cachedThrottle(
      () =>
        Utils.retry(
          () => {
            this.logger.debug(`Getting last block number`, ['ethereum', 'ethereum-blocks']);
            return this.eth.getBlockNumber();
          },
          {
            maxRetries: this.maxRetries,
            retryDelay: this.retryDelay,
          },
        )(),
      this.getLastBlockNumberMinDelay,
    );
  }