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

218
Visualizações
Async/Await promise being called twice

I'm trying to check if a connection exists after attempting to delete it. At this point the connection has already been deleted and it is now about to start checking once every second for 10 seconds. This is to make sure the user cant queue up multiple deletes before the first one has finished.

Everything seems to be working fine but I'm getting TWO Connection not found. Deleted successfully. I'm not quite sure why the resolve() portion of the code is being executed twice. Any help or advice would be great!

  // delete_network_status set to running
  // connection deleted

  return new Promise(async (resolve, reject) => {
    const checkDeleted = async (timeout_remaining) => {
      if (timeout_remaining <= 0) {
        ipc.server.broadcast("delete_network_status", "stopped");
        resolve();
      }
      try {
        // GetConnectionByUuid will fail if no connection exists
        await settings_iface.GetConnectionByUuid(toDeleteUUID);
      } catch (error) {
        console.log("Connection not found. Deleted successfully");
        ipc.server.broadcast("delete_network_status", "stopped");
        resolve();
      }
      console.log("Connection was found. Checking again...");
      await timeout(1000);
      await checkDeleted(timeout_remaining--);
    }
    
    //Set delay to 10 seconds
    await checkDeleted(10); 
  });
about 4 years ago · Juan Pablo Isaza
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