Skip to content

Commit 6001433

Browse files
mschauerJobJob
authored andcommitted
Allow setting max CHANNEL_SIZE with ENV variable
fixes #169
1 parent f354ff0 commit 6001433

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/core.jl

+8-5
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ const runner_task = Ref{Task}()
1414

1515
const run_remove_dead_nodes = Ref(false)
1616

17-
const CHANNEL_SIZE = 1024
18-
17+
const CHANNEL_SIZE = Ref(1024)
1918

2019
#run in asynchronous mode by default
2120
const async_mode = Ref(true)
@@ -224,7 +223,7 @@ immutable Message
224223
end
225224

226225
# Global channel for signal updates
227-
const _messages = Channel{Nullable{Message}}(CHANNEL_SIZE)
226+
const _messages = Channel{Nullable{Message}}(CHANNEL_SIZE[])
228227

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

@@ -255,8 +254,9 @@ end
255254

256255
function async_push!(n, x, onerror=print_error)
257256
taken = Base.n_avail(_messages)
258-
if taken >= CHANNEL_SIZE
259-
warn("Message queue is full. Ordering may be incorrect.")
257+
if taken >= CHANNEL_SIZE[]
258+
warn("Message queue is full. Ordering may be incorrect. "*
259+
"Channel size can be increased by setting `ENV[\"REACTIVE_CHANNEL_SIZE\"] = ...` before `using Reactive`.")
260260
@async put!(_messages, Message(n, x, onerror))
261261
else
262262
put!(_messages, Message(n, x, onerror))
@@ -414,5 +414,8 @@ function maybe_restart_queue()
414414
end
415415

416416
function __init__()
417+
if haskey(ENV, "REACTIVE_CHANNEL_SIZE")
418+
CHANNEL_SIZE[] = parse(Int, ENV["REACTIVE_CHANNEL_SIZE"])
419+
end
417420
runner_task[] = @async run()
418421
end

0 commit comments

Comments
 (0)