Expanding on the example from https://svelte.dev/tutorial/await-blocks, what is the conventional way to update numbers and use await blocks, or should await blocks be avoided altogether?
<script>
let numbers = [1, 2, 3]
async function getRandomNumber() {
const res = await fetch(`tutorial/random-number`);
const text = await res.text();
if (res.ok) {
return text;
} else {
throw new Error(text);
}
}
let promise = getRandomNumber();
function handleClick() {
promise = getRandomNumber();
}
</script>
<button on:click={handleClick}>
generate random number
</button>
{#each numbers as number}
<p>
{number}
</p>
{/each}
{#await promise}
<p>...waiting</p>
{:catch error}
<p style="color: red">{error.message}</p>
{/await}