mirror of
https://github.com/neovim/neovim
synced 2025-07-17 17:51:48 +00:00
fix(jobs): do not block UI when jobwait() doesn't block (#31803)
This commit is contained in:
@ -4177,8 +4177,6 @@ static void f_jobwait(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ui_busy_start();
|
|
||||||
ui_flush();
|
|
||||||
list_T *args = argvars[0].vval.v_list;
|
list_T *args = argvars[0].vval.v_list;
|
||||||
Channel **jobs = xcalloc((size_t)tv_list_len(args), sizeof(*jobs));
|
Channel **jobs = xcalloc((size_t)tv_list_len(args), sizeof(*jobs));
|
||||||
MultiQueue *waiting_jobs = multiqueue_new_parent(loop_on_put, &main_loop);
|
MultiQueue *waiting_jobs = multiqueue_new_parent(loop_on_put, &main_loop);
|
||||||
@ -4215,6 +4213,13 @@ static void f_jobwait(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
|||||||
before = os_hrtime();
|
before = os_hrtime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only mark the UI as busy when jobwait() blocks
|
||||||
|
const bool busy = remaining != 0;
|
||||||
|
if (busy) {
|
||||||
|
ui_busy_start();
|
||||||
|
ui_flush();
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < tv_list_len(args); i++) {
|
for (i = 0; i < tv_list_len(args); i++) {
|
||||||
if (remaining == 0) {
|
if (remaining == 0) {
|
||||||
break; // Timeout.
|
break; // Timeout.
|
||||||
@ -4256,7 +4261,9 @@ static void f_jobwait(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
|||||||
|
|
||||||
multiqueue_free(waiting_jobs);
|
multiqueue_free(waiting_jobs);
|
||||||
xfree(jobs);
|
xfree(jobs);
|
||||||
ui_busy_stop();
|
if (busy) {
|
||||||
|
ui_busy_stop();
|
||||||
|
}
|
||||||
tv_list_ref(rv);
|
tv_list_ref(rv);
|
||||||
rettv->v_type = VAR_LIST;
|
rettv->v_type = VAR_LIST;
|
||||||
rettv->vval.v_list = rv;
|
rettv->vval.v_list = rv;
|
||||||
|
@ -973,6 +973,39 @@ describe('jobs', function()
|
|||||||
feed('<CR>')
|
feed('<CR>')
|
||||||
fn.jobstop(api.nvim_get_var('id'))
|
fn.jobstop(api.nvim_get_var('id'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('does not set UI busy with zero timeout #31712', function()
|
||||||
|
local screen = Screen.new(50, 6)
|
||||||
|
command([[let g:id = jobstart(['sleep', '0.3'])]])
|
||||||
|
local busy = 0
|
||||||
|
screen._handle_busy_start = (function(orig)
|
||||||
|
return function()
|
||||||
|
orig(screen)
|
||||||
|
busy = busy + 1
|
||||||
|
end
|
||||||
|
end)(screen._handle_busy_start)
|
||||||
|
source([[
|
||||||
|
func PrintAndPoll()
|
||||||
|
echon "aaa\nbbb"
|
||||||
|
call jobwait([g:id], 0)
|
||||||
|
echon "\nccc"
|
||||||
|
endfunc
|
||||||
|
]])
|
||||||
|
feed_command('call PrintAndPoll()')
|
||||||
|
screen:expect {
|
||||||
|
grid = [[
|
||||||
|
|
|
||||||
|
{3: }|
|
||||||
|
aaa |
|
||||||
|
bbb |
|
||||||
|
ccc |
|
||||||
|
{6:Press ENTER or type command to continue}^ |
|
||||||
|
]],
|
||||||
|
}
|
||||||
|
feed('<CR>')
|
||||||
|
fn.jobstop(api.nvim_get_var('id'))
|
||||||
|
eq(0, busy)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
pending('exit event follows stdout, stderr', function()
|
pending('exit event follows stdout, stderr', function()
|
||||||
|
Reference in New Issue
Block a user