Hi, new Svelte user and new frontend developer here, I had a question regarding to a comment on the official Svelte tutorial. In the section on await blocks they talk about how Svelte avoids race conditions with promises by only considering the most recent promise. Specifically they say:
Only the most recent promise is considered, meaning you don't need to worry about race conditions.
I had a few questions related to this:
- How does Svelte internally track what the most recent promise is
- How does Svelte differentiate between separate promises? IE if I make 3 separate promises that affect 3 different, independent parts of the UI, does Svelte only consider the most recent of the 3, or can it handle them separately.
- Is there documentation/resources for me to learn more about this feature of Svelte? I couldn't find any on my own.
Thanks!
Top comments (1)
The most recent promise is merely the current value of the variable in the
{#await}
block. Change the value and Svelte immediately forgets to check on the previous promise the variable had.To #2: No. Separate variables.
As a front-end developer, what the lesson taught you is all that you need to know to successfully condition your UI based on the result of promises.