Skip to content

Commit c71f47a

Browse files
committed
chore: trim unused async utils
1 parent 06f3429 commit c71f47a

File tree

1 file changed

+1
-107
lines changed

1 file changed

+1
-107
lines changed

lua/nvim-tree/async.lua

Lines changed: 1 addition & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,6 @@ function M.in_async()
5151
return async_threads[thread] ~= nil
5252
end
5353

54-
---Wrap an asynchronous function to be directly called in synchronous context
55-
---@param func function
56-
---@param argc number The number of arguments the wrapped function accepts. Pass it if you want the returned function to receive an additional callback as final argument, and the signature of callback is the same as that of `async.exec`.
57-
---@return function
58-
function M.wrap(func, argc)
59-
return function(...)
60-
local args = { ... }
61-
if argc == nil or #args == argc then
62-
table.insert(args, function() end)
63-
end
64-
M.exec(func, unpack(args))
65-
end
66-
end
67-
6854
---Asynchronously call a function, which has callback as the last parameter (like luv apis)
6955
---@param func function
7056
---@param ... any
@@ -77,104 +63,12 @@ function M.call(func, ...)
7763
end)
7864
end
7965

80-
---Execuate multiple asynchronous function simultaneously
81-
---@param ... fun()
82-
---@return table[] (err, ...result) tuples from every function
83-
function M.all(...)
84-
local tasks = { ... }
85-
if #tasks == 0 then
86-
return {}
87-
end
88-
89-
local results = {}
90-
local finished = 0
91-
return co.yield(function(cb)
92-
for i, task in ipairs(tasks) do
93-
M.exec(task, function(...)
94-
finished = finished + 1
95-
results[i] = { ... }
96-
if finished == #tasks then
97-
cb(results)
98-
end
99-
end)
100-
end
101-
end)
102-
end
103-
10466
---Asynchronous `vim.schedule`
67+
---See `:h lua-loop-callbacks` and `:h api-fast`. Usually this should be used before `vim.api.*` and `vim.fn.*` calls.
10568
function M.schedule()
10669
return co.yield(function(cb)
10770
vim.schedule(cb)
10871
end)
10972
end
11073

111-
---@class Interrupter
112-
---@field yield fun()
113-
---@field interval number
114-
---@field last number
115-
local Interrupter = {}
116-
117-
---@return Interrupter
118-
function Interrupter.new(ms, yield)
119-
local obj = {
120-
interval = ms or 12,
121-
last = vim.loop.hrtime(),
122-
yield = yield or M.schedule,
123-
}
124-
setmetatable(obj, { __index = Interrupter })
125-
return obj
126-
end
127-
128-
function Interrupter:check()
129-
local cur = vim.loop.hrtime()
130-
if cur - self.last >= self.interval * 1000000 then
131-
self:yield()
132-
self.last = cur
133-
end
134-
end
135-
136-
M.Interrupter = Interrupter
137-
138-
---This is useful for cancelling execution async function
139-
---@class AbortSignal
140-
---@field aborted boolean
141-
---@field reason any
142-
---@field private abort_cbs function[]
143-
local AbortSignal = {}
144-
145-
---@return AbortSignal
146-
function AbortSignal.new()
147-
local obj = {
148-
aborted = false,
149-
reason = nil,
150-
abort_cbs = {},
151-
}
152-
153-
setmetatable(obj, { __index = AbortSignal })
154-
return obj
155-
end
156-
157-
function AbortSignal:abort(reason)
158-
if not self.aborted then
159-
self.aborted = true
160-
self.reason = reason
161-
for _, cb in pairs(self.abort_cbs) do
162-
cb(reason)
163-
end
164-
end
165-
end
166-
167-
---@param cb function
168-
function AbortSignal:on_abort(cb)
169-
table.insert(self.abort_cbs, cb)
170-
end
171-
172-
function AbortSignal:throw_if_aborted()
173-
if self.aborted then
174-
error(self.reason)
175-
end
176-
end
177-
178-
M.AbortSignal = AbortSignal
179-
18074
return M

0 commit comments

Comments
 (0)