File tree 3 files changed +23
-7
lines changed
3 files changed +23
-7
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ function Async:sleep(ms)
37
37
vim .defer_fn (function ()
38
38
self .sleeping = false
39
39
end , ms )
40
+ coroutine.yield ()
40
41
end
41
42
42
43
function Async :suspend ()
Original file line number Diff line number Diff line change @@ -197,7 +197,21 @@ function M.exec(cmd, opts)
197
197
lines = _lines
198
198
end ,
199
199
})
200
- vim .fn .jobwait ({ job })
200
+
201
+ if job <= 0 then
202
+ error (" Failed to start job: " .. vim .inspect (cmd ))
203
+ end
204
+
205
+ local Async = require (" lazy.async" )
206
+ local async = Async .current
207
+ if async then
208
+ while vim .fn .jobwait ({ job }, 0 )[1 ] == - 1 do
209
+ async :sleep (10 )
210
+ end
211
+ else
212
+ vim .fn .jobwait ({ job })
213
+ end
214
+
201
215
return lines
202
216
end
203
217
Original file line number Diff line number Diff line change @@ -217,16 +217,13 @@ function Task:spawn(cmd, opts)
217
217
self ._running :suspend ()
218
218
219
219
local running = true
220
- local ret = true
220
+ local ret = { ok = true , output = " " }
221
221
--- @param output string
222
222
function opts .on_exit (ok , output )
223
223
if not headless then
224
224
self :log (vim .trim (output ), ok and vim .log .levels .DEBUG or vim .log .levels .ERROR )
225
225
end
226
- if on_exit then
227
- pcall (on_exit , ok , output )
228
- end
229
- ret = ok
226
+ ret = { ok = ok , output = output }
230
227
running = false
231
228
self ._running :resume ()
232
229
end
@@ -241,7 +238,11 @@ function Task:spawn(cmd, opts)
241
238
Process .spawn (cmd , opts )
242
239
coroutine.yield ()
243
240
assert (not running , " process still running?" )
244
- return ret
241
+ if on_exit then
242
+ pcall (on_exit , ret .ok , ret .output )
243
+ end
244
+ coroutine.yield ()
245
+ return ret .ok
245
246
end
246
247
247
248
function Task :prefix ()
You can’t perform that action at this time.
0 commit comments