Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
ui: avoid "async race" with new client POST
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sclem committed Jan 17, 2020
1 parent 8fc4378 commit e176ae0
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ui/src/Clients.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e176ae0

Please sign in to comment.