Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

190
Views
Node.js use setInterval & clearInterval on a function

Hello is there a way to call a function with setInterval and clear the interval later?

Example: When I write in a chat !start the interval function should start with a interval. And when I write !stop in the chat the function with the interval on it should stop.

This is my function:

function abb(channel){
    console.log('Auto-Ban-Bot Timer running...')
    getChannelViewers(channel.replace('#','')).then(
        promise => {
            var vierwernames = promise.chatters.viewers;
            vierwernames.forEach(element => {
                checkFriendlyBots(element)
            });
        }
    );
}

I've tried many things but only got the !start command working, not the !stop command.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This is exactly what clearInterval() method does. It clears a timer set with the setInterval() method.

Check out this example:

const interval = setInterval(myTimer, 1000);
let i = 0;

function myTimer() {
  console.log(i++);
  if (i === 5){
    stop();
  }
}

function stop() {
  clearInterval(interval);
}

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!