ui: avoid "async race" with new client POST

The getClients() and POST request were being issued one after another
(not waiting for the POST to return). This can cause the GET /clients to
return the old list before the user config is updated. Waiting for the
POST to return before retrieving the new client list fixes the race.

This behavior can be reproduced by adding a time.Sleep(time.Second) to
the CreateClient server handler.
This commit is contained in:
sclem
2020-01-17 11:15:58 -05:00
parent 8fc4378316
commit e176ae04c2
+2 -1
View File
@@ -17,9 +17,10 @@
async function handleNewClick(event) {
const res = await fetch(clientsUrl, {
method: "POST",
}).then(getClients());
});
let newClient = await res.json();
console.log("New client added", newClient);
await getClients();
}
onMount(getClients);