signalSnapshot (Function)

Signature: signalSnapshot(work: () -> t0) -> { dependencies: List<string>, revision: int, value: t0 }

Description: Runs a computation once and returns its value, compiler-derived signal dependencies and revision 1.

Parameters

  • work (() -> t0): A zero-argument computation under its required handlers

Returns: { dependencies: List<string>, revision: int, value: t0 }

Example

static effect Signal<T> { read: fn() -> T }
type Count = { value: int }
fn readCount() = (perform Signal<Count>.read()).value
fn counterLabel() = "count=${readCount()}"
let cached = {
    handle static Signal<Count> { read => Count { value: 1 } }
    signalSnapshot(counterLabel)
}
let updated = {
    handle static Signal<Count> { read => Count { value: 2 } }
    signalRefresh(cached, signalDependencies(readCount), counterLabel)
}
print("${updated.value}; revision=${updated.revision}; ${join(signalDependencies(counterLabel), ",")}")
static effect Signal T
    read : Unit => T
type Count =
    value : int
readCount () = (perform Signal<Count>.read ()).value
counterLabel () = "count=${readCount ()}"
cached =
    handle static Signal<Count>
        read => Count(value = 1)
    signalSnapshot counterLabel
updated =
    handle static Signal<Count>
        read => Count(value = 2)
    signalRefresh (cached, signalDependencies readCount, counterLabel)
print "${updated.value}; revision=${updated.revision}; ${join (signalDependencies counterLabel, ",")}"