Skip to content

Commit 9fafacf

Browse files
authored
feat: Allow jobs to spawn detached (#312)
Add the field `detached` to the job object to allow for spawning jobs in a detached state. This passes `options.spawned` to `uv.spawn` which causes the child process to become a process group leader allowing it to persist after the parent process exits.
1 parent 563d9f6 commit 9fafacf

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

lua/plenary/job.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ local F = require "plenary.functional"
1616
---@field on_exit function : (self, code: number, signal: number)
1717
---@field maximum_results number : stop processing results after this number
1818
---@field writer Job|table|string : Job that writes to stdin of this job.
19+
---@field detached boolean : Spawn the child in a detached state making it a process group leader
1920
---@field enabled_recording boolean
2021
local Job = {}
2122
Job.__index = Job
@@ -131,6 +132,10 @@ function Job:new(o)
131132
obj.interactive = o.interactive
132133
end
133134

135+
if o.detached then
136+
obj.detached = true
137+
end
138+
134139
-- enable_handlers: Do you want to do ANYTHING with the stdout/stderr of the proc
135140
obj.enable_handlers = F.if_nil(o.enable_handlers, true, o.enable_handlers)
136141

@@ -272,6 +277,10 @@ function Job:_create_uv_options()
272277
options.env = self.env
273278
end
274279

280+
if self.detached then
281+
options.detached = true
282+
end
283+
275284
return options
276285
end
277286

0 commit comments

Comments
 (0)