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

212
Views
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
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!