perf: prevent active waiting in coroutines. suspend/resume instead

This commit is contained in:
Folke Lemaitre 2024-06-27 13:06:39 +02:00
parent 79bcc02d17
commit 68cee30cdb
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
3 changed files with 35 additions and 11 deletions

View file

@ -222,6 +222,8 @@ function Task:spawn(cmd, opts)
end
end
self._running:suspend()
local running = true
local ret = true
---@param output string
@ -234,6 +236,7 @@ function Task:spawn(cmd, opts)
end
ret = ok
running = false
self._running:resume()
end
if headless then
@ -244,9 +247,8 @@ function Task:spawn(cmd, opts)
end
end
Process.spawn(cmd, opts)
while running do
coroutine.yield()
end
coroutine.yield()
assert(not running, "process still running?")
return ret
end