mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge pull request #8031 from bfredl/gotintstatus
jobwait: return -2 on interrupt even with timeout
This commit is contained in:
commit
c57d315963
@ -151,7 +151,6 @@ void process_close_streams(Process *proc) FUNC_ATTR_NONNULL_ALL
|
|||||||
int process_wait(Process *proc, int ms, MultiQueue *events)
|
int process_wait(Process *proc, int ms, MultiQueue *events)
|
||||||
FUNC_ATTR_NONNULL_ARG(1)
|
FUNC_ATTR_NONNULL_ARG(1)
|
||||||
{
|
{
|
||||||
bool interrupted = false;
|
|
||||||
if (!proc->refcount) {
|
if (!proc->refcount) {
|
||||||
int status = proc->status;
|
int status = proc->status;
|
||||||
LOOP_PROCESS_EVENTS(proc->loop, proc->events, 0);
|
LOOP_PROCESS_EVENTS(proc->loop, proc->events, 0);
|
||||||
@ -173,7 +172,6 @@ int process_wait(Process *proc, int ms, MultiQueue *events)
|
|||||||
// we'll assume that a user frantically hitting interrupt doesn't like
|
// we'll assume that a user frantically hitting interrupt doesn't like
|
||||||
// the current job. Signal that it has to be killed.
|
// the current job. Signal that it has to be killed.
|
||||||
if (got_int) {
|
if (got_int) {
|
||||||
interrupted = true;
|
|
||||||
got_int = false;
|
got_int = false;
|
||||||
process_stop(proc);
|
process_stop(proc);
|
||||||
if (ms == -1) {
|
if (ms == -1) {
|
||||||
@ -184,14 +182,13 @@ int process_wait(Process *proc, int ms, MultiQueue *events)
|
|||||||
} else {
|
} else {
|
||||||
LOOP_PROCESS_EVENTS(proc->loop, events, 0);
|
LOOP_PROCESS_EVENTS(proc->loop, events, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
proc->status = -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (proc->refcount == 1) {
|
if (proc->refcount == 1) {
|
||||||
// Job exited, collect status and manually invoke close_cb to free the job
|
// Job exited, collect status and manually invoke close_cb to free the job
|
||||||
// resources
|
// resources
|
||||||
if (interrupted) {
|
|
||||||
proc->status = -2;
|
|
||||||
}
|
|
||||||
decref(proc);
|
decref(proc);
|
||||||
if (events) {
|
if (events) {
|
||||||
// the decref call created an exit event, process it now
|
// the decref call created an exit event, process it now
|
||||||
|
@ -497,7 +497,7 @@ describe('jobs', function()
|
|||||||
eq({'notification', 'wait', {{-3, 5}}}, next_msg())
|
eq({'notification', 'wait', {{-3, 5}}}, next_msg())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('will return -2 when interrupted', function()
|
it('will return -2 when interrupted without timeout', function()
|
||||||
feed_command('call rpcnotify(g:channel, "ready") | '..
|
feed_command('call rpcnotify(g:channel, "ready") | '..
|
||||||
'call rpcnotify(g:channel, "wait", '..
|
'call rpcnotify(g:channel, "wait", '..
|
||||||
'jobwait([jobstart("sleep 10; exit 55")]))')
|
'jobwait([jobstart("sleep 10; exit 55")]))')
|
||||||
@ -506,6 +506,15 @@ describe('jobs', function()
|
|||||||
eq({'notification', 'wait', {{-2}}}, next_msg())
|
eq({'notification', 'wait', {{-2}}}, next_msg())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('will return -2 when interrupted with timeout', function()
|
||||||
|
feed_command('call rpcnotify(g:channel, "ready") | '..
|
||||||
|
'call rpcnotify(g:channel, "wait", '..
|
||||||
|
'jobwait([jobstart("sleep 10; exit 55")], 10000))')
|
||||||
|
eq({'notification', 'ready', {}}, next_msg())
|
||||||
|
feed('<c-c>')
|
||||||
|
eq({'notification', 'wait', {{-2}}}, next_msg())
|
||||||
|
end)
|
||||||
|
|
||||||
it('can be called recursively', function()
|
it('can be called recursively', function()
|
||||||
if helpers.pending_win32(pending) then return end -- TODO: Need `cat`.
|
if helpers.pending_win32(pending) then return end -- TODO: Need `cat`.
|
||||||
source([[
|
source([[
|
||||||
|
Loading…
Reference in New Issue
Block a user