-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathtimeout.lua
More file actions
45 lines (45 loc) · 1.04 KB
/
timeout.lua
File metadata and controls
45 lines (45 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
---@type overseer.ComponentFileDefinition
return {
desc = "Cancel task if it exceeds a timeout",
params = {
timeout = {
desc = "Time to wait (in seconds) before canceling",
default = 120,
type = "integer",
validate = function(v)
return v > 0
end,
},
},
constructor = function(opts)
opts = opts or {}
vim.validate("timeout", opts.timeout, "number")
return {
timer = nil,
canceled = false,
on_start = function(self, task)
self.timer = vim.uv.new_timer()
self.timer:start(
1000 * opts.timeout,
0,
vim.schedule_wrap(function()
self.canceled = task:stop()
end)
)
end,
on_reset = function(self, task)
self.canceled = false
if self.timer then
self.timer:close()
self.timer = nil
end
end,
on_dispose = function(self, task)
if self.timer then
self.timer:close()
self.timer = nil
end
end,
}
end,
}