fix(util.spawn): correctly mark as faild on abort

This commit is contained in:
Folke Lemaitre 2025-03-01 07:54:16 +01:00
parent 9f0aa20489
commit 6917597f6d
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -57,13 +57,17 @@ end
function Proc:kill(signal)
close(self.stdout)
close(self.stderr)
if self:running() then
if not self.handle then
self.aborted = true
elseif self:running() then
self.handle:kill(signal or "sigterm")
end
end
function Proc:failed()
if self.aborted then
return true
end
if self:running() then
return false
end
@ -98,6 +102,9 @@ end
function Proc:run()
assert(not self.handle, "already running")
if self.aborted then
return self:on_exit()
end
self.stdout = assert(uv.new_pipe())
self.stderr = assert(uv.new_pipe())
self.data = { [self.stdout] = {}, [self.stderr] = {} }
@ -179,7 +186,7 @@ function Proc:on_exit()
close(self.stdout)
close(self.stderr)
if self.opts.on_exit then
self.opts.on_exit(self, self.code ~= 0 or self.signal ~= 0)
self.opts.on_exit(self, self.code ~= 0 or self.signal ~= 0 or self.aborted or false)
end
end)
end