Skip to content

Commit

Permalink
Merge pull request #178 from JuliaGizmos/sd/07
Browse files Browse the repository at this point in the history
changes for 0.7
  • Loading branch information
SimonDanisch committed Jun 7, 2018
2 parents 6001433 + 1418b26 commit 705f3f7
Show file tree
Hide file tree
Showing 15 changed files with 315 additions and 307 deletions.
2 changes: 1 addition & 1 deletion REQUIRE
@@ -1,2 +1,2 @@
julia 0.5
julia 0.6
DataStructures
4 changes: 2 additions & 2 deletions appveyor.yml
@@ -1,7 +1,7 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"

Expand Down
2 changes: 0 additions & 2 deletions src/Reactive.jl
Expand Up @@ -7,6 +7,4 @@ include("operators.jl")
include("async.jl")
include("time.jl")

include("deprecation.jl")

end # module
41 changes: 30 additions & 11 deletions src/core.jl
Expand Up @@ -27,9 +27,14 @@ const edges = Vector{Int}[] #parents to children, useful for plotting graphs

const node_count = Dict{String, Int}() #counts of different signals for naming

if VERSION < v"0.7.0-alpha.2"
const wait07 = wait
else
const wait07 = fetch
end

if !debug_memory
type Signal{T}
mutable struct Signal{T}
id::Int # also its index into `nodes`, and `edges`
value::T
parents::Tuple
Expand All @@ -48,7 +53,7 @@ if !debug_memory
end
end
else
type Signal{T}
mutable struct Signal{T}
id::Int
value::T
parents::Tuple
Expand Down Expand Up @@ -215,15 +220,29 @@ end
set_value!(node::Signal, x) = (node.value = x)

##### Messaging #####

immutable Message
struct Message
node
value
onerror::Function
end

struct NullException <: Exception
end
# Global channel for signal updates
const _messages = Channel{Nullable{Message}}(CHANNEL_SIZE[])
struct MaybeMessage
isnull::Bool
data::Message
MaybeMessage() = new(true)
MaybeMessage(m::Message) = new(false, m)
end

Base.get(x::MaybeMessage) = isnull(x) ? throw(NullException()) : x.data
if VERSION < v"0.7.0-alpha.2"
import Base: isnull
end
isnull(x::MaybeMessage) = x.isnull
Base.convert(::Type{MaybeMessage}, x::Message) = MaybeMessage(x)

const _messages = Channel{MaybeMessage}(CHANNEL_SIZE[])

run_async(async::Bool) = (async_mode[] = async)

Expand Down Expand Up @@ -265,7 +284,7 @@ function async_push!(n, x, onerror=print_error)
end

function break_loop()
put!(_messages, Nullable{Message}())
put!(_messages, MaybeMessage())
end

function stop()
Expand All @@ -274,7 +293,7 @@ function stop()
# it seems to take a long time until the runner_task is actually finished
# which can be enough to run into maybe_restart_queue with !isdone(runner_task)
# see #144
wait(runner_task[])
wait07(runner_task[])
end

"""
Expand Down Expand Up @@ -399,14 +418,14 @@ function maybe_restart_queue()
# will happen if `add_action!` is called while processing a push!
prev_runner = current_task()
@async begin
# new runner should wait for current runner to process the
# new runner should wait07 for current runner to process the
# break_loop (null) message
wait(prev_runner)
wait07(prev_runner)
runner_task[] = current_task()
run()
end
else
wait(runner_task[])
wait07(runner_task[])
runner_task[] = @async run()
end
end
Expand Down
12 changes: 0 additions & 12 deletions src/deprecation.jl

This file was deleted.

1 change: 0 additions & 1 deletion test/REQUIRE

This file was deleted.

14 changes: 7 additions & 7 deletions test/async.jl
@@ -1,19 +1,19 @@
facts("Async") do
@testset "Async" begin

context("async_map") do
@testset "async_map" begin
x = Signal(1; name="x")
t, y = async_map(-, 0, x)
z = map(yv->2yv, y; name="z")

@fact value(t) --> nothing
@fact value(y) --> 0
@fact value(z) --> 0
@test (value(t)) == (nothing)
@test (value(y)) == (0)
@test (value(z)) == (0)

push!(x, 2)
step()
step()

@fact value(y) --> -2
@fact value(z) --> -4
@test (value(y)) == (-2)
@test (value(z)) == (-4)
end
end

0 comments on commit 705f3f7

Please sign in to comment.