0

I have an api that takes 4 mins(approx.) to get completed in my polymer application. When I send the request at exact 2mins another request gets sent even after timeout and debounce-duration is set to 10 mins. I want to stop that second request sent or wait for the first request to get completed. Some suggested me to use fetch instead of iron-ajax. I need a fix in iron-ajax itself. Can I have a solution for this.

code goes here

<iron-ajax id="request"
       url={{request}}
       verbose
       handle-as="json"
       method="{{method}}"
       body="{{body}}"
       params="{{requestParams}}"
       on-error="onError"
       loading="{{loading}}"
       timeout=600000
       content-type="application/json"
       debounce-duration=600000
       last-error="{{lastError}}"
       last-response="{{lastResponse}}">

I hope this will get resolved. Thanks in advance

1 Answers1

0

You can set a Boolean variable in order to able call this.$.request.generateRequest() something like:

DEMO

static get properties() {return {
    _isRequest: {
         type: Boolean,
         value: true}}}

static get observers(){ return ['_checkLastResponse(lastResponse)'] }

__checkLastResponse(r) {
        // we have received a response from iron-ajax so allow for next call
        if (r) this._isRequest = true;}

// As you provided above code, you call ajax manually. 
_ajax_call() {
      if (this._isRequest) {
              this.$.request.generateRequest();
              this._isRequest = false; }
}

static get template() { return `
   <paper-button disabled="[[!_isReruest]]" on-tap="ajax_call">AJAX CALL</paper-button>
   .......
   `;}

So, you may remove the unnecessary properties something like debounce-duration=600000 etc.

Cappittall
  • 3,300
  • 3
  • 15
  • 23
  • HakanC.Thanks for the solution. Yes `debounce-duration` is not at all necessary in this scene, as it will be good to use only if the request is sent **automatically** and not **manually**. I will try as you suggested and let you know the outcome. – Roopesh Manchanbele Jan 04 '19 at 07:31