Skip to content

Commit

Permalink
add spawn to free input reader from sticky repl task
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth committed Jun 14, 2024
1 parent 45dc422 commit e7d2dea
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions stdlib/REPL/src/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2823,22 +2823,23 @@ keymap_data(ms::MIState, m::ModalInterface) = keymap_data(state(ms), mode(ms))

function prompt!(term::TextTerminal, prompt::ModalInterface, s::MIState = init_state(term, prompt))
Base.reseteof(term)
l = Base.ReentrantLock()
t1 = Threads.@spawn :interactive while true
wait(s.async_channel)
status = @lock l begin
fcn = take!(s.async_channel)
fcn(s)
end
status (:ok, :ignore) || break
end
raw!(term, true)
enable_bracketed_paste(term)
try
activate(prompt, s, term, term)
old_state = mode(s)
l = Base.ReentrantLock()
t = @async while true
wait(s.async_channel)
status = @lock l begin
fcn = take!(s.async_channel)
fcn(s)
end
status (:ok, :ignore) || break
end
Base.errormonitor(t)
while true
# spawn this because the main repl task is sticky (due to use of @async and _wait2)
# and we want to not block typing when the repl task thread is busy
t2 = Threads.@spawn :interactive while true
eof(term) || peek(term, Char) # wait before locking but don't consume
@lock l begin
kmap = keymap(s, prompt)
Expand Down Expand Up @@ -2873,7 +2874,10 @@ function prompt!(term::TextTerminal, prompt::ModalInterface, s::MIState = init_s
end
end
end
return fetch(t2)
finally
put!(s.async_channel, Returns(:done))
wait(t1)
raw!(term, false) && disable_bracketed_paste(term)
end
# unreachable
Expand Down

0 comments on commit e7d2dea

Please sign in to comment.