Skip to content

Commit a0d9a9a

Browse files
add spawn to free input reader from sticky repl task
1 parent 45dc422 commit a0d9a9a

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

stdlib/REPL/src/LineEdit.jl

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2823,22 +2823,23 @@ keymap_data(ms::MIState, m::ModalInterface) = keymap_data(state(ms), mode(ms))
28232823

28242824
function prompt!(term::TextTerminal, prompt::ModalInterface, s::MIState = init_state(term, prompt))
28252825
Base.reseteof(term)
2826+
l = Base.ReentrantLock()
2827+
t1 = Threads.@spawn :interactive while true
2828+
wait(s.async_channel)
2829+
status = @lock l begin
2830+
fcn = take!(s.async_channel)
2831+
fcn(s)
2832+
end
2833+
status (:ok, :ignore) || break
2834+
end
28262835
raw!(term, true)
28272836
enable_bracketed_paste(term)
28282837
try
28292838
activate(prompt, s, term, term)
28302839
old_state = mode(s)
2831-
l = Base.ReentrantLock()
2832-
t = @async while true
2833-
wait(s.async_channel)
2834-
status = @lock l begin
2835-
fcn = take!(s.async_channel)
2836-
fcn(s)
2837-
end
2838-
status (:ok, :ignore) || break
2839-
end
2840-
Base.errormonitor(t)
2841-
while true
2840+
# spawn this because the main repl task is sticky (due to use of @async and _wait2)
2841+
# and we want to not block typing when the repl task thread is busy
2842+
t2 = Threads.@spawn :interactive while true
28422843
eof(term) || peek(term, Char) # wait before locking but don't consume
28432844
@lock l begin
28442845
kmap = keymap(s, prompt)
@@ -2873,7 +2874,10 @@ function prompt!(term::TextTerminal, prompt::ModalInterface, s::MIState = init_s
28732874
end
28742875
end
28752876
end
2877+
wait(t2)
28762878
finally
2879+
put!(s.async_channel, Returns(:done))
2880+
wait(t1)
28772881
raw!(term, false) && disable_bracketed_paste(term)
28782882
end
28792883
# unreachable

0 commit comments

Comments
 (0)