Skip to content

Commit 1fcb7d9

Browse files
committed
Merge remote-tracking branch 'origin/next' into next
2 parents 402a776 + 664a929 commit 1fcb7d9

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

src/core.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ Base.show(io::IO, n::Node) =
6565
write(io, "Node{$(eltype(n))}($(n.value), nactions=$(length(n.actions))$(n.alive ? "" : ", closed"))")
6666

6767
value(n::Node) = n.value
68+
value(::Void) = false
6869
eltype{T}(::Node{T}) = T
6970
eltype{T}(::Type{Node{T}}) = T
7071

@@ -142,6 +143,7 @@ function _push!(n, x, onerror=print_error)
142143
end
143144
nothing
144145
end
146+
_push!(::Void, x, onerror=print_error) = nothing
145147

146148
# remove messages from the channel and propagate them
147149
global run

src/time.jl

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,16 @@ function fpswhen(switch, rate)
5959
end
6060

6161
function setup_next_tick(outputref, switchref, dt, wait_dt)
62-
weakrefdo(switchref, value, ()->false) && Timer(t -> begin
63-
weakrefdo(switchref, value, ()->false) &&
64-
weakrefdo(outputref, x -> push!(x, dt))
65-
end, wait_dt)
66-
end
67-
68-
function weakrefdo(ref, yes, no=()->nothing)
69-
ref.value != nothing ? yes(ref.value) : no()
62+
if value(switchref.value)
63+
Timer(t -> if value(switchref.value)
64+
_push!(outputref, dt)
65+
end, wait_dt)
66+
end
7067
end
7168

7269
function fpswhen_connect(rate, switch, output)
73-
let prev_time = time(),
74-
dt = 1.0/rate,
70+
let prev_time = time()
71+
dt = 1.0/rate
7572
outputref = WeakRef(output)
7673
switchref = WeakRef(switch)
7774
switch_ticks = filter(x->x, false, switch) # only turn-ons
@@ -80,7 +77,7 @@ function fpswhen_connect(rate, switch, output)
8077
for inp in [output, switch_ticks]
8178
add_action!(inp, output) do output, timestep
8279
start_time = time()
83-
setup_next_tick(outputref, switchref, time()-prev_time, dt)
80+
setup_next_tick(outputref, switchref, start_time-prev_time, dt)
8481
prev_time = start_time
8582
end
8683
end

0 commit comments

Comments
 (0)