You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte/packages/svelte/tests/runtime-runes/samples/async-stale-read-many-sources/main.svelte

24 lines
550 B

<script>
let show = $state(false);
let items = $state(Array.from({ length: 2000 }, (_, i) => i));
const deferred = [];
function delay(v) {
if (!v) return v;
return new Promise((resolve) => deferred.push(() => resolve(v)));
}
</script>
<button onclick={() => (show = true)}>show</button>
<button onclick={() => items.forEach((_, i) => items[i]++)}>items</button>
<button onclick={() => deferred.shift()?.()}>shift</button>
<p>{await delay(items[0])}</p>
{#if await delay(show)}
<div>
{#each items as item}{item},{/each}
</div>
{/if}