timer
timer
in ,

Creating a Pool out Timer in Javascript / Typescript

If you are stuck in pooling the request and need a timer just use these simple line of code.

  poolOutTimer(poolTime: number) {
    let timeLeft:number = poolTime;
    var timerId = setInterval(countdown, 1000);
    function countdown() {
      if (timeLeft == 0) {
        clearTimeout(timerId);
        //do something here for stop..
        console.log("Time UP : ");

      } else {
        //do something here while in progress..
        console.log("Time Left : ", timeLeft);
        timeLeft--;
        if (timeLeft%5==0) {
          console.log("Make New request here..");
          
        } else {
          console.log("Request Under Process..");          
        }
      }
    }
  }

Just For typescript or if you are using ionic with dynamic loader, I created this to show message on loader

Here loading:any; is a variable declared for loader.

poolOutTimer(poolTime: number) {
    this.timeLeft = poolTime;
    this.timerId = setInterval(()=>this.countdown(), 1000);
    this.showLoading();
  
  }

  countdown() {
   
    if (this.timeLeft == 0) {
      clearTimeout(this.timerId);
      //do something here for stop..
        console.log("Time UP : ");
        this.loading.dismiss();

    } else {
      //do something here while in progress..
      console.log("Time Left : ", this.timeLeft);
      this.timeLeft--;
      if (this.timeLeft%5==0) {
        console.log("Make New request here..");
        this.loading.setContent("New request");
    
        
      } else {
        console.log("Request Under Process..");     
        this.loading.setContent("Under Process");
       
      }
    }
  }


  showLoading() {
    this.loading = this.loadingCtrl.create({
      content: this.constant.loadingString
    });
    this.loading.present();
  }

Author Profile

PREM KUMAR
PREM KUMAR
Hey Its..! Tech Lover , Ionic, Angular, Typescript, Dotnet Core, Node, Like Opencv, AI, ML, Robotics, Iot, Love Music, Cooking, Girls, Innovation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

What do you think?

400 Points
Upvote Downvote
bulkdml

Common challenges while using bulk collect and techniques to to deal with it

What is Big Data? Why it become a hot topic in IT industry?