From aafd18f58d906c6a7833135afb440976e8c36f65 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Tue, 24 May 2016 02:32:41 -0500 Subject: [PATCH 1/3] Add option to specify type of throttle Signal --- src/time.jl | 4 ++-- test/time.jl | 13 ++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/time.jl b/src/time.jl index 40df1f6..3bfb0f3 100644 --- a/src/time.jl +++ b/src/time.jl @@ -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 diff --git a/test/time.jl b/test/time.jl index 1d7e150..d9ab178 100644 --- a/test/time.jl +++ b/test/time.jl @@ -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 - From 6621ef30e11591479d7c189ab63b763000b6f219 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Tue, 24 May 2016 07:32:25 -0500 Subject: [PATCH 2/3] Suppress warnings on julia-0.5 --- src/deprecation.jl | 4 +++- test/call_count.jl | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/deprecation.jl b/src/deprecation.jl index 36a5455..a28d0e7 100644 --- a/src/deprecation.jl +++ b/src/deprecation.jl @@ -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 diff --git a/test/call_count.jl b/test/call_count.jl index e59275a..7076d36 100644 --- a/test/call_count.jl +++ b/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) From d7a2bd36ead56cf1e0bdad6b04af9e6a1803860b Mon Sep 17 00:00:00 2001 From: Shashi Gowda Date: Tue, 24 May 2016 23:11:28 +0530 Subject: [PATCH 3/3] name the signal in push! inside push! test to prevent gc --- test/basics.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/basics.jl b/test/basics.jl index 5a4bf61..f90a7ee 100644 --- a/test/basics.jl +++ b/test/basics.jl @@ -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