mirror of https://github.com/sveltejs/svelte
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.
23 lines
411 B
23 lines
411 B
6 years ago
|
<script>
|
||
6 years ago
|
let promise;
|
||
6 years ago
|
|
||
6 years ago
|
function findAnswer() {
|
||
6 years ago
|
promise = new Promise(fulfil => {
|
||
6 years ago
|
const delay = 1000 + Math.random() * 3000;
|
||
|
setTimeout(() => fulfil(42), delay);
|
||
|
});
|
||
6 years ago
|
}
|
||
|
</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}
|
||
6 years ago
|
{/if}
|