Reference · Jobs and services

unwatched

signature
unwatched(fn) -> any

What it does

Calls the function and gives what it gives, without following what it read: the tables, the global variables and the watch calls inside it do not make the running live loader run again. For data a loader needs but should not follow, such as who is signed in, or a table it reads by one row while watching a topic of its own. See Live data.

Examples

in a program
server fn load_inbox() {    let me = unwatched(() => me())                        // the sessions table wakes nothing    db.query("select * from messages where to_id = ?", me.id)}server fn load_posts(thread: int) {    watch(`thread:${thread}`)    unwatched(() => db.query("select * from posts where thread = ?", thread))}
print(unwatched(() => 42))print(unwatched(() => session()))
output
42{}

Edge cases

print(unwatched(() => err("no")) ?? "fallback")print(unwatched(() => unwatched(() => [1, 2]) | map((n) => n * 10)))
output
fallback[10, 20]

Errors

An argument that is not a function, or no argument, is a runtime error, not an error value. A runtime error inside the function is the call's.

this one fails
print(unwatched(42))
output
line 1: `unwatched` expects a function as argument 1, got int

Chaining

The function is its first argument, so unwatched wraps a read rather than taking a pipeline. Its value goes on into one:

print(unwatched(() => ["ann", "bob"]) | map(upper))
output
["ANN", "BOB"]

See also

watch, publish, live, session

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

Thread 0 posts

On unwatched(): 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