Reference · Browser

run_after

signature
run_after(num, fn) -> null

What it does

In the browser, calls f once, ms milliseconds on, and gives null at once. If the component that started it leaves the page first, f is not called: the timer goes with its component, its row or its branch. It may be called from an event handler, from @mount, or from the component's code. On the server it does nothing.

Examples

in a program
component Saved() {    state shown = false    <div>        <button @click={() => {            shown = true            run_after(3000, () => { shown = false })    // hides it again in 3 s        }}>Save</button>        {shown && <span>Saved</span>}    </div>}
in a program
component Toast(text, on_close) {    <p class="toast" @mount={(_el) => { run_after(4000, on_close) }}>{text}</p>}

Edge cases

Errors

A milliseconds that is not a number, or something not a function, is an error in the browser's console, and quillo check says so first.

in a program
run_after("soon", () => {})    // `quillo check`: argument 1 of `run_after` must be num, got str

Chaining

run_after is a statement: its function is where the work goes.

See also

every, page_updated, sleep

Thread
2Useful? Like it, or add to its thread below.

Thread 0 posts

On run_after(): questions, tips, corrections, and code that uses it.

No posts yet. The first one opens the thread.

    Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo