Set Interval ID changes on event call












0















Situation!



Here is a sample reproduction of the problem at hand with setting the interval's Id and retrieving the same. There are 3 separate events that are called based on button clicks.



One of the event is a POST request using axios. The second process is basically an async function awaiting the POST request to complete.



Each interval is assigned to a variable of the class, and when a process is called the other process's are cleared to avoid unnecessary polling to the django view.



All works great with single clicks of each process button.



The Problem?



SInce there are 3 separate buttons for each event, there might be a possibility to click on one of the buttons again which triggers another event to take place and also ends the other event, BUT , the process doesn't seem to end on a consecutive click of the same button.



Event Loop




  • Button 1 is clicked. ( All works good. )

  • Button 2 is clicked. ( All works good. Everyone is happy. )

  • Button 3 is clicked. ( All works good. Again. )





  • Button 1 is clicked. ( All works good. )

  • Button 1 is clicked. ( All works good. Again. )

  • Button 2 is clicked. ( Process 1 hasn't been cleared. Process two has started concurrently. )


  • Button 1 is clicked. ( Process 1 and 2 are running concurrently. ) < Referring to the last two events that took place.





Now as we have seen for some reason the other event loop doesn't seem to end on consecutive clicks. It looks like the ID's are overwritten and the clear interval can't find the interval anymore once they have been overwritten.



Sample code



class Handler {

constructor () {
this.interval1 = 0;
this.interval2 = 0;
this.interval3 = 0;
}

getToken(name) {
var cookieValue = null;
if (document.cookie && document.cookie !== '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}

process_one () {
clearInterval(this.interval2);


this.interval1 = setInterval(function() {
console.log(" Polling 1. ")
},300);
}

async process_two () {
clearInterval(this.interval1);


var scope_obj = this;
this.interval2 = setInterval(async function() {
console.log(" Polling 2. ");
var data = await scope_obj.process_three();
}, 500);
}

async process_three () {
return axios( {
url: "",
data:{"data":"LOL"},
headers : {
'X-CSRFToken': this.getToken('csrftoken'),
'Content-Type': 'application/x-www-form-urlencoded'
}
} )
}
}

let event = new Handler();

$("#p1").click(function() {
console.log("P1 started.")
event.process_one ();
})

$("#p2").click(async function() {
console.log("P2 started.")
event.process_two ();

})

$("#p3").click(function() {
console.log("P3 started.")
event.process_three ();
})


HTML Code.



<div class="row">
<div class="col-lg-12">
<button type="button" class="btn btn-warning" id="p1">P1</button>
<button type="button" class="btn btn-warning" id="p2">P2</button>
<button type="button" class="btn btn-warning" id="p3">P3</button>
</div>
</div>









share|improve this question



























    0















    Situation!



    Here is a sample reproduction of the problem at hand with setting the interval's Id and retrieving the same. There are 3 separate events that are called based on button clicks.



    One of the event is a POST request using axios. The second process is basically an async function awaiting the POST request to complete.



    Each interval is assigned to a variable of the class, and when a process is called the other process's are cleared to avoid unnecessary polling to the django view.



    All works great with single clicks of each process button.



    The Problem?



    SInce there are 3 separate buttons for each event, there might be a possibility to click on one of the buttons again which triggers another event to take place and also ends the other event, BUT , the process doesn't seem to end on a consecutive click of the same button.



    Event Loop




    • Button 1 is clicked. ( All works good. )

    • Button 2 is clicked. ( All works good. Everyone is happy. )

    • Button 3 is clicked. ( All works good. Again. )





    • Button 1 is clicked. ( All works good. )

    • Button 1 is clicked. ( All works good. Again. )

    • Button 2 is clicked. ( Process 1 hasn't been cleared. Process two has started concurrently. )


    • Button 1 is clicked. ( Process 1 and 2 are running concurrently. ) < Referring to the last two events that took place.





    Now as we have seen for some reason the other event loop doesn't seem to end on consecutive clicks. It looks like the ID's are overwritten and the clear interval can't find the interval anymore once they have been overwritten.



    Sample code



    class Handler {

    constructor () {
    this.interval1 = 0;
    this.interval2 = 0;
    this.interval3 = 0;
    }

    getToken(name) {
    var cookieValue = null;
    if (document.cookie && document.cookie !== '') {
    var cookies = document.cookie.split(';');
    for (var i = 0; i < cookies.length; i++) {
    var cookie = jQuery.trim(cookies[i]);
    // Does this cookie string begin with the name we want?
    if (cookie.substring(0, name.length + 1) === (name + '=')) {
    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
    break;
    }
    }
    }
    return cookieValue;
    }

    process_one () {
    clearInterval(this.interval2);


    this.interval1 = setInterval(function() {
    console.log(" Polling 1. ")
    },300);
    }

    async process_two () {
    clearInterval(this.interval1);


    var scope_obj = this;
    this.interval2 = setInterval(async function() {
    console.log(" Polling 2. ");
    var data = await scope_obj.process_three();
    }, 500);
    }

    async process_three () {
    return axios( {
    url: "",
    data:{"data":"LOL"},
    headers : {
    'X-CSRFToken': this.getToken('csrftoken'),
    'Content-Type': 'application/x-www-form-urlencoded'
    }
    } )
    }
    }

    let event = new Handler();

    $("#p1").click(function() {
    console.log("P1 started.")
    event.process_one ();
    })

    $("#p2").click(async function() {
    console.log("P2 started.")
    event.process_two ();

    })

    $("#p3").click(function() {
    console.log("P3 started.")
    event.process_three ();
    })


    HTML Code.



    <div class="row">
    <div class="col-lg-12">
    <button type="button" class="btn btn-warning" id="p1">P1</button>
    <button type="button" class="btn btn-warning" id="p2">P2</button>
    <button type="button" class="btn btn-warning" id="p3">P3</button>
    </div>
    </div>









    share|improve this question

























      0












      0








      0








      Situation!



      Here is a sample reproduction of the problem at hand with setting the interval's Id and retrieving the same. There are 3 separate events that are called based on button clicks.



      One of the event is a POST request using axios. The second process is basically an async function awaiting the POST request to complete.



      Each interval is assigned to a variable of the class, and when a process is called the other process's are cleared to avoid unnecessary polling to the django view.



      All works great with single clicks of each process button.



      The Problem?



      SInce there are 3 separate buttons for each event, there might be a possibility to click on one of the buttons again which triggers another event to take place and also ends the other event, BUT , the process doesn't seem to end on a consecutive click of the same button.



      Event Loop




      • Button 1 is clicked. ( All works good. )

      • Button 2 is clicked. ( All works good. Everyone is happy. )

      • Button 3 is clicked. ( All works good. Again. )





      • Button 1 is clicked. ( All works good. )

      • Button 1 is clicked. ( All works good. Again. )

      • Button 2 is clicked. ( Process 1 hasn't been cleared. Process two has started concurrently. )


      • Button 1 is clicked. ( Process 1 and 2 are running concurrently. ) < Referring to the last two events that took place.





      Now as we have seen for some reason the other event loop doesn't seem to end on consecutive clicks. It looks like the ID's are overwritten and the clear interval can't find the interval anymore once they have been overwritten.



      Sample code



      class Handler {

      constructor () {
      this.interval1 = 0;
      this.interval2 = 0;
      this.interval3 = 0;
      }

      getToken(name) {
      var cookieValue = null;
      if (document.cookie && document.cookie !== '') {
      var cookies = document.cookie.split(';');
      for (var i = 0; i < cookies.length; i++) {
      var cookie = jQuery.trim(cookies[i]);
      // Does this cookie string begin with the name we want?
      if (cookie.substring(0, name.length + 1) === (name + '=')) {
      cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
      break;
      }
      }
      }
      return cookieValue;
      }

      process_one () {
      clearInterval(this.interval2);


      this.interval1 = setInterval(function() {
      console.log(" Polling 1. ")
      },300);
      }

      async process_two () {
      clearInterval(this.interval1);


      var scope_obj = this;
      this.interval2 = setInterval(async function() {
      console.log(" Polling 2. ");
      var data = await scope_obj.process_three();
      }, 500);
      }

      async process_three () {
      return axios( {
      url: "",
      data:{"data":"LOL"},
      headers : {
      'X-CSRFToken': this.getToken('csrftoken'),
      'Content-Type': 'application/x-www-form-urlencoded'
      }
      } )
      }
      }

      let event = new Handler();

      $("#p1").click(function() {
      console.log("P1 started.")
      event.process_one ();
      })

      $("#p2").click(async function() {
      console.log("P2 started.")
      event.process_two ();

      })

      $("#p3").click(function() {
      console.log("P3 started.")
      event.process_three ();
      })


      HTML Code.



      <div class="row">
      <div class="col-lg-12">
      <button type="button" class="btn btn-warning" id="p1">P1</button>
      <button type="button" class="btn btn-warning" id="p2">P2</button>
      <button type="button" class="btn btn-warning" id="p3">P3</button>
      </div>
      </div>









      share|improve this question














      Situation!



      Here is a sample reproduction of the problem at hand with setting the interval's Id and retrieving the same. There are 3 separate events that are called based on button clicks.



      One of the event is a POST request using axios. The second process is basically an async function awaiting the POST request to complete.



      Each interval is assigned to a variable of the class, and when a process is called the other process's are cleared to avoid unnecessary polling to the django view.



      All works great with single clicks of each process button.



      The Problem?



      SInce there are 3 separate buttons for each event, there might be a possibility to click on one of the buttons again which triggers another event to take place and also ends the other event, BUT , the process doesn't seem to end on a consecutive click of the same button.



      Event Loop




      • Button 1 is clicked. ( All works good. )

      • Button 2 is clicked. ( All works good. Everyone is happy. )

      • Button 3 is clicked. ( All works good. Again. )





      • Button 1 is clicked. ( All works good. )

      • Button 1 is clicked. ( All works good. Again. )

      • Button 2 is clicked. ( Process 1 hasn't been cleared. Process two has started concurrently. )


      • Button 1 is clicked. ( Process 1 and 2 are running concurrently. ) < Referring to the last two events that took place.





      Now as we have seen for some reason the other event loop doesn't seem to end on consecutive clicks. It looks like the ID's are overwritten and the clear interval can't find the interval anymore once they have been overwritten.



      Sample code



      class Handler {

      constructor () {
      this.interval1 = 0;
      this.interval2 = 0;
      this.interval3 = 0;
      }

      getToken(name) {
      var cookieValue = null;
      if (document.cookie && document.cookie !== '') {
      var cookies = document.cookie.split(';');
      for (var i = 0; i < cookies.length; i++) {
      var cookie = jQuery.trim(cookies[i]);
      // Does this cookie string begin with the name we want?
      if (cookie.substring(0, name.length + 1) === (name + '=')) {
      cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
      break;
      }
      }
      }
      return cookieValue;
      }

      process_one () {
      clearInterval(this.interval2);


      this.interval1 = setInterval(function() {
      console.log(" Polling 1. ")
      },300);
      }

      async process_two () {
      clearInterval(this.interval1);


      var scope_obj = this;
      this.interval2 = setInterval(async function() {
      console.log(" Polling 2. ");
      var data = await scope_obj.process_three();
      }, 500);
      }

      async process_three () {
      return axios( {
      url: "",
      data:{"data":"LOL"},
      headers : {
      'X-CSRFToken': this.getToken('csrftoken'),
      'Content-Type': 'application/x-www-form-urlencoded'
      }
      } )
      }
      }

      let event = new Handler();

      $("#p1").click(function() {
      console.log("P1 started.")
      event.process_one ();
      })

      $("#p2").click(async function() {
      console.log("P2 started.")
      event.process_two ();

      })

      $("#p3").click(function() {
      console.log("P3 started.")
      event.process_three ();
      })


      HTML Code.



      <div class="row">
      <div class="col-lg-12">
      <button type="button" class="btn btn-warning" id="p1">P1</button>
      <button type="button" class="btn btn-warning" id="p2">P2</button>
      <button type="button" class="btn btn-warning" id="p3">P3</button>
      </div>
      </div>






      javascript jquery async-await axios setinterval






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 19 at 2:44









      pratprat

      32




      32
























          2 Answers
          2






          active

          oldest

          votes


















          0














          You are indeed overwriting the ID.



          When you click P1 the second time, you don't clear the related interval timer before overwriting interval1. The earlier instance continues to run in the background but, since you overwrote interval1, you lost the ID for it. At that point you have two interval timers running for P1 but you only have an ID for the most recent one.



          When you click P2, it stops the recent P1 interval but the earlier P1 interval is still running in the background.






          share|improve this answer































            0














            The answer from Ouroborus was correct. Before I started the process I had a line that ends the other process but wasn't ending the correct process. Printing out the ID helped me understand that the ID's were being overwritten.



              class Handler {

            constructor () {
            this.interval1 = 0;
            this.interval2 = 0;
            this.interval3 = 0;
            }

            getToken(name) {
            var cookieValue = null;
            if (document.cookie && document.cookie !== '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
            var cookie = jQuery.trim(cookies[i]);
            // Does this cookie string begin with the name we want?
            if (cookie.substring(0, name.length + 1) === (name + '=')) {
            cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
            break;
            }
            }
            }
            return cookieValue;
            }

            process_one () {
            clearInterval(this.interval2); // Clear the other interval.
            clearInterval(this.interval1); // Clear the current interval.

            this.interval1 = setInterval(function() {
            console.log(" Polling 1. ")
            },300);
            }

            async process_two () {
            clearInterval(this.interval1); // Clear the other interval.
            clearInterval(this.interval2); // Clear the current interval.

            var scope_obj = this;
            this.interval2 = setInterval(async function() {
            console.log(" Polling 2. ");
            var data = await scope_obj.process_three();
            }, 500);
            }

            async process_three () {
            return axios( {
            url: "",
            data:{"data":"LOL"},
            headers : {
            'X-CSRFToken': this.getToken('csrftoken'),
            'Content-Type': 'application/x-www-form-urlencoded'
            }
            } )
            }
            }


            The other parts of the code remain the same.






            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54263660%2fset-interval-id-changes-on-event-call%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              You are indeed overwriting the ID.



              When you click P1 the second time, you don't clear the related interval timer before overwriting interval1. The earlier instance continues to run in the background but, since you overwrote interval1, you lost the ID for it. At that point you have two interval timers running for P1 but you only have an ID for the most recent one.



              When you click P2, it stops the recent P1 interval but the earlier P1 interval is still running in the background.






              share|improve this answer




























                0














                You are indeed overwriting the ID.



                When you click P1 the second time, you don't clear the related interval timer before overwriting interval1. The earlier instance continues to run in the background but, since you overwrote interval1, you lost the ID for it. At that point you have two interval timers running for P1 but you only have an ID for the most recent one.



                When you click P2, it stops the recent P1 interval but the earlier P1 interval is still running in the background.






                share|improve this answer


























                  0












                  0








                  0







                  You are indeed overwriting the ID.



                  When you click P1 the second time, you don't clear the related interval timer before overwriting interval1. The earlier instance continues to run in the background but, since you overwrote interval1, you lost the ID for it. At that point you have two interval timers running for P1 but you only have an ID for the most recent one.



                  When you click P2, it stops the recent P1 interval but the earlier P1 interval is still running in the background.






                  share|improve this answer













                  You are indeed overwriting the ID.



                  When you click P1 the second time, you don't clear the related interval timer before overwriting interval1. The earlier instance continues to run in the background but, since you overwrote interval1, you lost the ID for it. At that point you have two interval timers running for P1 but you only have an ID for the most recent one.



                  When you click P2, it stops the recent P1 interval but the earlier P1 interval is still running in the background.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 19 at 3:21









                  OuroborusOuroborus

                  6,4191534




                  6,4191534

























                      0














                      The answer from Ouroborus was correct. Before I started the process I had a line that ends the other process but wasn't ending the correct process. Printing out the ID helped me understand that the ID's were being overwritten.



                        class Handler {

                      constructor () {
                      this.interval1 = 0;
                      this.interval2 = 0;
                      this.interval3 = 0;
                      }

                      getToken(name) {
                      var cookieValue = null;
                      if (document.cookie && document.cookie !== '') {
                      var cookies = document.cookie.split(';');
                      for (var i = 0; i < cookies.length; i++) {
                      var cookie = jQuery.trim(cookies[i]);
                      // Does this cookie string begin with the name we want?
                      if (cookie.substring(0, name.length + 1) === (name + '=')) {
                      cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                      break;
                      }
                      }
                      }
                      return cookieValue;
                      }

                      process_one () {
                      clearInterval(this.interval2); // Clear the other interval.
                      clearInterval(this.interval1); // Clear the current interval.

                      this.interval1 = setInterval(function() {
                      console.log(" Polling 1. ")
                      },300);
                      }

                      async process_two () {
                      clearInterval(this.interval1); // Clear the other interval.
                      clearInterval(this.interval2); // Clear the current interval.

                      var scope_obj = this;
                      this.interval2 = setInterval(async function() {
                      console.log(" Polling 2. ");
                      var data = await scope_obj.process_three();
                      }, 500);
                      }

                      async process_three () {
                      return axios( {
                      url: "",
                      data:{"data":"LOL"},
                      headers : {
                      'X-CSRFToken': this.getToken('csrftoken'),
                      'Content-Type': 'application/x-www-form-urlencoded'
                      }
                      } )
                      }
                      }


                      The other parts of the code remain the same.






                      share|improve this answer




























                        0














                        The answer from Ouroborus was correct. Before I started the process I had a line that ends the other process but wasn't ending the correct process. Printing out the ID helped me understand that the ID's were being overwritten.



                          class Handler {

                        constructor () {
                        this.interval1 = 0;
                        this.interval2 = 0;
                        this.interval3 = 0;
                        }

                        getToken(name) {
                        var cookieValue = null;
                        if (document.cookie && document.cookie !== '') {
                        var cookies = document.cookie.split(';');
                        for (var i = 0; i < cookies.length; i++) {
                        var cookie = jQuery.trim(cookies[i]);
                        // Does this cookie string begin with the name we want?
                        if (cookie.substring(0, name.length + 1) === (name + '=')) {
                        cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                        break;
                        }
                        }
                        }
                        return cookieValue;
                        }

                        process_one () {
                        clearInterval(this.interval2); // Clear the other interval.
                        clearInterval(this.interval1); // Clear the current interval.

                        this.interval1 = setInterval(function() {
                        console.log(" Polling 1. ")
                        },300);
                        }

                        async process_two () {
                        clearInterval(this.interval1); // Clear the other interval.
                        clearInterval(this.interval2); // Clear the current interval.

                        var scope_obj = this;
                        this.interval2 = setInterval(async function() {
                        console.log(" Polling 2. ");
                        var data = await scope_obj.process_three();
                        }, 500);
                        }

                        async process_three () {
                        return axios( {
                        url: "",
                        data:{"data":"LOL"},
                        headers : {
                        'X-CSRFToken': this.getToken('csrftoken'),
                        'Content-Type': 'application/x-www-form-urlencoded'
                        }
                        } )
                        }
                        }


                        The other parts of the code remain the same.






                        share|improve this answer


























                          0












                          0








                          0







                          The answer from Ouroborus was correct. Before I started the process I had a line that ends the other process but wasn't ending the correct process. Printing out the ID helped me understand that the ID's were being overwritten.



                            class Handler {

                          constructor () {
                          this.interval1 = 0;
                          this.interval2 = 0;
                          this.interval3 = 0;
                          }

                          getToken(name) {
                          var cookieValue = null;
                          if (document.cookie && document.cookie !== '') {
                          var cookies = document.cookie.split(';');
                          for (var i = 0; i < cookies.length; i++) {
                          var cookie = jQuery.trim(cookies[i]);
                          // Does this cookie string begin with the name we want?
                          if (cookie.substring(0, name.length + 1) === (name + '=')) {
                          cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                          break;
                          }
                          }
                          }
                          return cookieValue;
                          }

                          process_one () {
                          clearInterval(this.interval2); // Clear the other interval.
                          clearInterval(this.interval1); // Clear the current interval.

                          this.interval1 = setInterval(function() {
                          console.log(" Polling 1. ")
                          },300);
                          }

                          async process_two () {
                          clearInterval(this.interval1); // Clear the other interval.
                          clearInterval(this.interval2); // Clear the current interval.

                          var scope_obj = this;
                          this.interval2 = setInterval(async function() {
                          console.log(" Polling 2. ");
                          var data = await scope_obj.process_three();
                          }, 500);
                          }

                          async process_three () {
                          return axios( {
                          url: "",
                          data:{"data":"LOL"},
                          headers : {
                          'X-CSRFToken': this.getToken('csrftoken'),
                          'Content-Type': 'application/x-www-form-urlencoded'
                          }
                          } )
                          }
                          }


                          The other parts of the code remain the same.






                          share|improve this answer













                          The answer from Ouroborus was correct. Before I started the process I had a line that ends the other process but wasn't ending the correct process. Printing out the ID helped me understand that the ID's were being overwritten.



                            class Handler {

                          constructor () {
                          this.interval1 = 0;
                          this.interval2 = 0;
                          this.interval3 = 0;
                          }

                          getToken(name) {
                          var cookieValue = null;
                          if (document.cookie && document.cookie !== '') {
                          var cookies = document.cookie.split(';');
                          for (var i = 0; i < cookies.length; i++) {
                          var cookie = jQuery.trim(cookies[i]);
                          // Does this cookie string begin with the name we want?
                          if (cookie.substring(0, name.length + 1) === (name + '=')) {
                          cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                          break;
                          }
                          }
                          }
                          return cookieValue;
                          }

                          process_one () {
                          clearInterval(this.interval2); // Clear the other interval.
                          clearInterval(this.interval1); // Clear the current interval.

                          this.interval1 = setInterval(function() {
                          console.log(" Polling 1. ")
                          },300);
                          }

                          async process_two () {
                          clearInterval(this.interval1); // Clear the other interval.
                          clearInterval(this.interval2); // Clear the current interval.

                          var scope_obj = this;
                          this.interval2 = setInterval(async function() {
                          console.log(" Polling 2. ");
                          var data = await scope_obj.process_three();
                          }, 500);
                          }

                          async process_three () {
                          return axios( {
                          url: "",
                          data:{"data":"LOL"},
                          headers : {
                          'X-CSRFToken': this.getToken('csrftoken'),
                          'Content-Type': 'application/x-www-form-urlencoded'
                          }
                          } )
                          }
                          }


                          The other parts of the code remain the same.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jan 19 at 10:43









                          pratprat

                          32




                          32






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54263660%2fset-interval-id-changes-on-event-call%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Liquibase includeAll doesn't find base path

                              How to use setInterval in EJS file?

                              Petrus Granier-Deferre