Skip to content

Commit b76a05f

Browse files
authored
Merge pull request #100 from JuliaDatabases/tan/subs
fix: avoid worldage issue in subscription callback
2 parents 5caa605 + 9bc8c0e commit b76a05f

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ Multiple channels can be subscribed together by providing a `Dict{String, Functi
133133
x = Any[]
134134
f(y::SubscriptionMessage) = push!(x, y.message)
135135
sub = open_subscription(conn)
136-
d = Dict{String, Function}({"baz" => f, "bar" => y->println(y.message)})
136+
d = Dict{String, Function}("baz" => f, "bar" => y->println(y.message))
137137
subscribe(sub, d)
138138
publish(conn, "baz", "foobar")
139139
x # Returns ["foobar"]

src/client.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ function subscription_loop(conn::SubscriptionConnection, err_callback::Function)
165165
reply = convert_reply(reply)
166166
message = SubscriptionMessage(reply)
167167
if message.message_type == SubscriptionMessageType.Message
168-
conn.callbacks[message.channel](message)
168+
Base.invokelatest(conn.callbacks[message.channel], message)
169169
elseif message.message_type == SubscriptionMessageType.Pmessage
170-
conn.pcallbacks[message.channel](message)
170+
Base.invokelatest(conn.pcallbacks[message.channel], message)
171171
end
172172
catch err
173173
err_callback(err)

test/redis_tests.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,9 @@ end
404404
subscribe(subs, "duplicate", y->f(y.message))
405405
@test publish(conn, "channel", "hello, world!") > 0 #Number of connected clients returned
406406
@test publish(conn, "channel", "Okay, bye!") > 0 #Number of connected clients returned
407+
@test publish(conn, "duplicate", "hello world 2") > 0 #Number of connected clients returned
407408
sleep(2)
408-
@test x == ["hello, world!", "Okay, bye!"]
409+
@test x == ["hello, world!", "Okay, bye!", "hello world 2"]
409410

410411
# following command prints ("Invalid response received: ")
411412
disconnect(subs)

0 commit comments

Comments
 (0)