Closed Shinkyuuu closed 2 years ago
I might take this back
This is true, using await is indeed another way of saying .then(). The difference is that using await
will pause the whole function execution until the promise settles. Using .then()
will let the function continue but won't call the code within .then()
until the promise settles.
I believe our current implementation is equivalent to calling await twice.
const response = await fetch(`/api/lobbys/${game_code}/${player_id}`)
.then(response => response.json());
The await pauses our function execution until the awaited function (fetch
) is complete. However, adding .then()
to the end of it also has the function await for its completion as well I think
Resource: https://dev.to/masteringjs/using-then-vs-async-await-in-javascript-2pma
https://github.com/uri-planetarium/interactive-planetarium-ERAU/blob/a2e557b38e2e0513f49a3f2f9d210dbcc38ad87b/player_client/src/components/joinGame/join_game.js#L59-L64
I think that having
await
in front of an asynchronous function call eliminates the need of using.then()
afterwards. If such is the case, remove the.then()
as it makes increases readabilityBe sure fix every instance of this issue