Created
June 4, 2016 05:52
-
-
Save penntaylor/a4dd1ed268b2401e54a72705954180c5 to your computer and use it in GitHub Desktop.
# Altered version of @femtotrader's minimal signal/slot implementation on top of Reactive.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Altered version of @femtotrader's minimal signal/slot implementation on top of Reactive.jl | |
# Changes to: | |
# 1. Signal() | |
# 2. emit() | |
# 3. connect() | |
using Reactive | |
Signal() = Reactive.Signal(Tuple{Tuple, Array{Any}}, ((), Any[])) | |
typealias Slot Function | |
function emit(signal::Reactive.Signal, args...; kwargs...) | |
push!(signal, (args, kwargs)) | |
end | |
function myslot01(args...; kwargs...) | |
println("$(time()) myslot01 with $args and $kwargs") | |
end | |
function connect(signal::Reactive.Signal, slott::Slot) | |
c = map(signal) do a | |
slott(a[1]...; a[2]...) | |
end | |
preserve(c) | |
end | |
stop_modified = Signal() | |
connect(stop_modified, myslot01) | |
emit(stop_modified, 1, 2, x=3, y=4) | |
emit(stop_modified, 10, 20, x=30, y=40) | |
emit(stop_modified, 9, x=1, y=2, z=3, s=7, t=8, u=9) | |
emit(stop_modified) | |
# Ensure Reactive processes all remaining events | |
while(isready(Reactive._messages)) | |
yield() | |
end | |
println("") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment