diff --git a/base/util.jl b/base/util.jl index 9c9afbe0053b7..68ccbdc25d5cc 100644 --- a/base/util.jl +++ b/base/util.jl @@ -309,14 +309,10 @@ Proceed? y/n [n] timeout 5 seconds: timed out See also `Base.getpass` and `Base.winprompt` for secure entry of passwords. """ function prompt(input::IO, output::IO, message::AbstractString; default::AbstractString="", timeout::Union{Nothing, Real} = nothing) - timedout = false - uinput_entered = false - if !isnothing(timeout) && timeout > 0 + timeout_timer = if !isnothing(timeout) && timeout > 0 plural = timeout == 1 ? "" : "s" msg = !isempty(default) ? "$message [$default] timeout $timeout second$(plural): " : "$message: " Timer(timeout) do t - uinput_entered && return - timedout = true lock(input.cond) input.status = Base.StatusEOF notify(input.cond) @@ -324,14 +320,17 @@ function prompt(input::IO, output::IO, message::AbstractString; default::Abstrac end else msg = !isempty(default) ? "$message [$default]: " : "$message: " + nothing end print(output, msg) uinput = readline(input, keep=true) - if timedout - println(output, "timed out") - return default - else - uinput_entered = true # disable timeout action + if !isnothing(timeout_timer) + if isopen(timeout_timer) + close(timeout_timer) + else + println(output, "timed out") + return default + end end isempty(uinput) && return nothing # Encountered an EOF uinput = chomp(uinput)