Skip to content

Commit

Permalink
Merge pull request #97 from JuliaLang/teh/throttle_typ
Browse files Browse the repository at this point in the history
Add option to specify type of throttle Signal
  • Loading branch information
shashi committed May 25, 2016
2 parents 4d4417f + d7a2bd3 commit 0c032a3
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/deprecation.jl
Expand Up @@ -10,4 +10,6 @@ export lift, consume, foldl, keepwhen, keepif, dropif, dropwhen
@deprecate keepif filter
@deprecate dropif(f, default, signal) filter(x -> !f(x), default, signal)
@deprecate dropwhen(predicate, x, signal) filterwhen(map(!, predicate), x, signal)
@deprecate call{T}(::Type{Signal{T}}, x) Signal(T, x)
if VERSION < v"0.5.0-dev"
@deprecate call{T}(::Type{Signal{T}}, x) Signal(T, x)
end
4 changes: 2 additions & 2 deletions src/time.jl
Expand Up @@ -12,8 +12,8 @@ For example
will create vectors of updates to the integer signal `x` which occur within 0.2 second time windows.
"""
function throttle{T}(dt, node::Signal{T}, f=(acc, x) -> x, init=value(node), reinit=x->x)
output = Signal(init, (node,))
function throttle{T}(dt, node::Signal{T}, f=(acc,x)->x, init=value(node), reinit=x->x; typ=typeof(init))
output = Signal(typ, init, (node,))
throttle_connect(dt, output, node, f, init, reinit)
output
end
Expand Down
2 changes: 1 addition & 1 deletion test/basics.jl
Expand Up @@ -171,7 +171,7 @@ facts("Basic checks") do
context("push! inside push!") do
a = Signal(0)
b = Signal(1)
map(x -> push!(a, x), b)
Reactive.preserve(map(x -> push!(a, x), b))

@fact value(a) --> 0

Expand Down
4 changes: 3 additions & 1 deletion test/call_count.jl
@@ -1,5 +1,7 @@

number() = rand(0:100)
if !isdefined(:number)
number() = rand(0:100)
end

facts("Call counting") do
a = Signal(0)
Expand Down
13 changes: 12 additions & 1 deletion test/time.jl
Expand Up @@ -116,6 +116,17 @@ facts("Timing functions") do
@fact value(y) --> 1
@fact value(z′) --> 2
@fact value(y′) --> Int[3,2,1]

# type safety
s1 = Signal(3)
s2 = Signal(rand(2,2))
m = merge(s1, s2)
t = throttle(1/60, m; typ=Any)
r = rand(3,3)
push!(s2, r)
Reactive.run(1)
sleep(0.05)
Reactive.run(1)
@fact value(t) --> r
end
end

0 comments on commit 0c032a3

Please sign in to comment.