Browse Source

* Fixed race condition in player headers fetch

master
vvandenb 2 years ago
parent
commit
2c4f61d3f7
  1. 25
      front/volume/src/components/Pong/GameComponent.svelte

25
front/volume/src/components/Pong/GameComponent.svelte

@ -29,26 +29,25 @@
$: { $: {
if (game && game.players.length > 1) { if (game && game.players.length > 1) {
getGameUsers(); void getGameUsers();
} }
} }
function getGameUsers() { async function getGameUsers() {
gameUsers = []; gameUsers = [];
game.players.forEach(player => { for (const player of game.players) {
fetch(API_URL + "/users/" + player.name + "/byname", { console.log(player.name)
const response = await fetch(API_URL + "/users/" + player.name + "/byname", {
credentials: "include", credentials: "include",
method: "GET", method: "GET",
mode: "cors", mode: "cors",
}).then((response) => { })
if (response.ok) { if (response.ok) {
response.json().then((user) => { const user = await response.json()
gameUsers.push(user); gameUsers.push(user);
gameUsers = gameUsers; }
}); }
} gameUsers = gameUsers;
});
});
} }
</script> </script>

Loading…
Cancel
Save