mirror of https://github.com/sveltejs/svelte
24 lines
527 B
24 lines
527 B
<script>
|
|
export let promise;
|
|
|
|
// [svelte-upgrade suggestion]
|
|
// review these functions and remove unnecessary 'export' keywords
|
|
export function findAnswer() {
|
|
promise = new Promise(fulfil => {
|
|
const delay = 1000 + Math.random() * 3000;
|
|
setTimeout(() => fulfil(42), delay);
|
|
});
|
|
}
|
|
</script>
|
|
|
|
<button on:click='{findAnswer}'>find the answer</button>
|
|
|
|
{#if promise}
|
|
{#await promise}
|
|
<p>wait for it...</p>
|
|
{:then answer}
|
|
<p>the answer is {answer}!</p>
|
|
{:catch error}
|
|
<p>well that's odd</p>
|
|
{/await}
|
|
{/if} |