You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lua/nvim-tree/async.lua
+1-107Lines changed: 1 addition & 107 deletions
Original file line number
Diff line number
Diff line change
@@ -51,20 +51,6 @@ function M.in_async()
51
51
returnasync_threads[thread] ~=nil
52
52
end
53
53
54
-
---Wrap an asynchronous function to be directly called in synchronous context
55
-
---@paramfuncfunction
56
-
---@paramargcnumber 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
-
---@returnfunction
58
-
functionM.wrap(func, argc)
59
-
returnfunction(...)
60
-
localargs= { ... }
61
-
ifargc==nilor#args==argcthen
62
-
table.insert(args, function() end)
63
-
end
64
-
M.exec(func, unpack(args))
65
-
end
66
-
end
67
-
68
54
---Asynchronously call a function, which has callback as the last parameter (like luv apis)
69
55
---@paramfuncfunction
70
56
---@param ... any
@@ -77,104 +63,12 @@ function M.call(func, ...)
77
63
end)
78
64
end
79
65
80
-
---Execuate multiple asynchronous function simultaneously
81
-
---@param ... fun()
82
-
---@returntable[] (err, ...result) tuples from every function
83
-
functionM.all(...)
84
-
localtasks= { ... }
85
-
if#tasks==0then
86
-
return {}
87
-
end
88
-
89
-
localresults= {}
90
-
localfinished=0
91
-
returnco.yield(function(cb)
92
-
fori, taskinipairs(tasks) do
93
-
M.exec(task, function(...)
94
-
finished=finished+1
95
-
results[i] = { ... }
96
-
iffinished==#tasksthen
97
-
cb(results)
98
-
end
99
-
end)
100
-
end
101
-
end)
102
-
end
103
-
104
66
---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.
105
68
functionM.schedule()
106
69
returnco.yield(function(cb)
107
70
vim.schedule(cb)
108
71
end)
109
72
end
110
73
111
-
---@classInterrupter
112
-
---@fieldyieldfun()
113
-
---@fieldintervalnumber
114
-
---@fieldlastnumber
115
-
localInterrupter= {}
116
-
117
-
---@returnInterrupter
118
-
functionInterrupter.new(ms, yield)
119
-
localobj= {
120
-
interval=msor12,
121
-
last=vim.loop.hrtime(),
122
-
yield=yieldorM.schedule,
123
-
}
124
-
setmetatable(obj, { __index=Interrupter })
125
-
returnobj
126
-
end
127
-
128
-
functionInterrupter:check()
129
-
localcur=vim.loop.hrtime()
130
-
ifcur-self.last>=self.interval*1000000then
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
0 commit comments