'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);
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
