diff --git a/stdlib/REPL/src/REPLCompletions.jl b/stdlib/REPL/src/REPLCompletions.jl index 3a441540c3620..4179819e47f1d 100644 --- a/stdlib/REPL/src/REPLCompletions.jl +++ b/stdlib/REPL/src/REPLCompletions.jl @@ -335,21 +335,23 @@ PATH_cache_condition::Union{Threads.Condition, Nothing} = nothing # used for syn next_cache_update::Float64 = 0.0 function maybe_spawn_cache_PATH() global PATH_cache_task, PATH_cache_condition, next_cache_update - # Extract to local variables to enable flow-sensitive type inference for these global variables - PATH_cache_task_local = PATH_cache_task - PATH_cache_condition_local = PATH_cache_condition @lock PATH_cache_lock begin + # Extract to local variables to enable flow-sensitive type inference for these global variables + PATH_cache_task_local = PATH_cache_task PATH_cache_task_local isa Task && !istaskdone(PATH_cache_task_local) && return time() < next_cache_update && return - PATH_cache_task = Threads.@spawn begin - REPLCompletions.cache_PATH() - @lock PATH_cache_lock begin - next_cache_update = time() + 10 # earliest next update can run is 10s after - PATH_cache_task = nothing # release memory when done - PATH_cache_condition_local !== nothing && notify(PATH_cache_condition_local) + PATH_cache_task = PATH_cache_task_local = Threads.@spawn begin + try + REPLCompletions.cache_PATH() + finally + @lock PATH_cache_lock begin + next_cache_update = time() + 10 # earliest next update can run is 10s after + PATH_cache_task = nothing # release memory when done + PATH_cache_condition_local = PATH_cache_condition + PATH_cache_condition_local !== nothing && notify(PATH_cache_condition_local) + end end end - PATH_cache_task_local = PATH_cache_task Base.errormonitor(PATH_cache_task_local) end end diff --git a/stdlib/REPL/test/replcompletions.jl b/stdlib/REPL/test/replcompletions.jl index 7b2b032af77d3..1b6dad2d17a00 100644 --- a/stdlib/REPL/test/replcompletions.jl +++ b/stdlib/REPL/test/replcompletions.jl @@ -1095,7 +1095,7 @@ function test_only_arm_cache_refresh() # force the next cache update to happen immediately REPL.REPLCompletions.next_cache_update = 0 end - return REPL.REPLCompletions.PATH_cache_condition + return nothing end function test_only_wait_cache_path_done()