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

102
Visualizações
More elegant way to handle progress update notifications

Hi i'm currently tracking the uploading of a file (as it compresses) and sending the progress back to the user through the GUI. My code is somewhat ugly-looking. Wondering if you guys might have a better way?

The booleans below are meant to prevent constant updates as i only want to update at certain 'checkpoints'. (in this case below, 25%, 50% and 75%).

let past25 = false;
let past50 = false;
let past75 = false;

ffmpeg(file.path)
.addOption('-hls_time', 10)
.addOption('-hls_list_size', 0)
.addOption('-f', 'hls')
.on('progress', (progress) => {
    let sendUpdate = false;

    if (progress.percent > 25 && past25 == false) {
        sendUpdate = past25 = true;
    } else if (progress.percent > 50 && past50 == false) {
        sendUpdate = past25 = past50 = true;
    } else if (progress.percent > 75 && past75 == false) {
        sendUpdate = past25 = past50 = past75 = true;
    }

    if (sendUpdate) {
        notifyUser(progress)
    }
})
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Perhaps set an initial threshold and an increment and then use a single check. Also allows you to change the granularity of your updates by just changing the values.

let threshold = 25;
let increment = 25;

ffmpeg(file.path)
  .addOption('-hls_time', 10)
  .addOption('-hls_list_size', 0)
  .addOption('-f', 'hls')
  .on('progress', (progress) => {

    if (progress.percent > threshold) {
      notifyUser(progress);
      // account for skipping multiple 'checkpoints' by rounding to the next highest threshold
      threshold += Math.ceil((progress.percent - threshold) / increment) * increment;
    }

  });
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