Skip to content

Temporarily disabling throttling #19

@faune

Description

@faune

Hi there,
Cool plugin for superagent! But I think I introduced a bug into https://github.com/faune/homebridge-grohe-sense while integrating this plugin. My plugin has an option to enable/disable throttling in its config, and I believe I incorrectly implemented this using:

    // Throttling support for HTTP requests
    this.throttle = new Throttle({
      'active': this.config['throttle_support'],        // set false to pause queue
      'rate': this.config['throttle_rate'],             // how many requests can be sent every `ratePer`
      'ratePer': this.config['throttle_rateper'],       // number of ms in which `rate` requests may be sent
      'concurrent': this.config['throttle_concurrent'], // how many requests can be sent concurrently
    });

If active is set to false, it seems all requests are paused.

I have a generic getURL() function called with an URI endpoint like this:

private async getURL(url: string) {
    if (!this.accessToken) {
      this.log.error('getURL(): Cannot call getURL() before an access token has been acquired');
    }
    this.log.debug('getURL(): GET: ', url);
    
    return new Promise<superagent.Response>((resolve, reject) => {
      superagent
        .get(url)
        .use(this.throttle.plugin())
        .set('Content-Type', 'application/json')
        .set('Authorization', `Bearer ${this.accessToken}`)
        .set('accept', 'json')
        .end((err, res) => {
          if (err) {
            const errMsg = `getURL(): Unexpected server response: ${err}`;
            reject(errMsg);
          } else {
            resolve(res);
          }
        });
    });
  }

How can I still keep this generic getURL() function which sets .use(this.throttle.plugin()) and keep it optional if a user wants to enable/disable throttling?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions