Skip to content

Latest commit

 

History

History
41 lines (34 loc) · 1.47 KB

README.md

File metadata and controls

41 lines (34 loc) · 1.47 KB

PullObservables

Stable Dev Build Status Coverage

The problems with eager or push updating in Observables.jl are:

  • updating multiple observables in sequence fails if they're mapped together and are only valid after all are changed to their new state
  • every update traverses the whole computation graph it's connected to, potentially wasting a lot of resources if the result is not used

PullObservables solve these issues by only recomputing their values once requested (pulled). Here's an example:

using PullObservables

x = PullObservable([1, 2, 3])
y = PullObservable([4, 5, 6])
z = PullObservable{Vector{Int}}()
map!(z, x, y) do x, y
    println("Computing z")
    x .+ y
end
@show z[]

println("Updating x")
x[] = [1, 2, 3, 4]
println("Updating y")
y[] = [4, 5, 6, 7]
@show z[]
Computing z
z[] = [5, 7, 9]
Updating x
Updating y
Computing z
z[] = [5, 7, 9, 11]