Sleep

A function that returns a promise that resolves after a given amount of time. This function is similar to the

sleep function in Python
.

Usage

<script>
    import {sleep} from "@sveu/shared"

    let text = "wake up"

    async function update_text(){
        text = "sleep...."
        await sleep(2)
        text = "wake up"
    }
</script>

<h1>{text}</h1>

<button on:click="{() => update_text()}">Sleep</button>
<script>
    import {sleep} from "@sveu/shared"

    let text = "wake up"

    async function update_text(){
        text = "sleep...."
        await sleep(2)
        text = "wake up"
    }
</script>

<h1>{text}</h1>

<button on:click="{() => update_text()}">Sleep</button>
svelte

Example

wake up

<script>
    import {sleep} from "@sveu/shared"

    let text = "wake up"

    async function update_text(){
        text = "sleep...."
        await sleep(2)
        text = "wake up"
    }
</script>

<div class="flex flex-col mx-20 mt-20 text-center">
<h1>{text}</h1>

<button on:click="{() => update_text()}">Sleep</button>
</div>
<script>
    import {sleep} from "@sveu/shared"

    let text = "wake up"

    async function update_text(){
        text = "sleep...."
        await sleep(2)
        text = "wake up"
    }
</script>

<div class="flex flex-col mx-20 mt-20 text-center">
<h1>{text}</h1>

<button on:click="{() => update_text()}">Sleep</button>
</div>
svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Click fold/expand code

API

Arguments

Name Description Type Required
s Seconds to sleep number Yes
throwOnTimeout Throw an error on timeout boolean No
reason Reason to throw if throwOnTimeout is true. string No