Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

280
Visualizações
How to call a function/notification at specific offset/interval durations in JavaScript?

In my recent project, I came across a situation where I have to send a notifications to client based on specific schedule. For an example: schedule value is 8s,14s,20s then first notification will be send after 8s, next is on 14s and last is on 20s. How can we achieve this functionality?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I would do something like this:

function scheduleNotification(seconds){
  setTimeout(function(){
    // your logic here
    // you could also pass a callback to be executed here
  }, seconds * 1000);
}

function sendNotifications(){
  scheduleNotification(8);
  scheduleNotification(14);
  scheduleNotification(20);
}

sendNotifications();
about 4 years ago · Juan Pablo Isaza Relatório

0

You can do something like this:

const intervalDuration = [8, 14, 20]; // you can add or delete intervals

for (let i = 0, len = intervalDuration.length; i < len; i++) {
      setTimeout(\* function *\, intervalDuration[i] * 1000);
}

Here, you can add multiple interval based on your requirement. For your use case, setTimeout is the only option as you need to call notifications on different intervals.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda