fix: detect async context more robustly (#254)

This commit is contained in:
JINNOUCHI Yasushi 2024-08-28 21:58:36 +09:00 committed by GitHub
parent 476f70e1b0
commit 38f2a2207e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 3 deletions

View File

@ -21,7 +21,8 @@ local frecency = setmetatable({}, {
return function(...) return function(...)
if not instance() then if not instance() then
rawset(self, "instance", require("frecency.klass").new()) rawset(self, "instance", require("frecency.klass").new())
instance():setup() local is_async = key == "delete" or key == "validate_database" or key == "register"
instance():setup(is_async)
end end
return instance()[key](instance(), ...) return instance()[key](instance(), ...)
end end

View File

@ -23,8 +23,9 @@ Frecency.new = function()
end end
---This is called when `:Telescope frecency` is called at the first time. ---This is called when `:Telescope frecency` is called at the first time.
---@param is_async boolean
---@return nil ---@return nil
function Frecency:setup() function Frecency:setup(is_async)
---@async ---@async
local function init() local function init()
timer.track "init() start" timer.track "init() start"
@ -36,7 +37,6 @@ function Frecency:setup()
timer.track "init() finish" timer.track "init() finish"
end end
local is_async = not not coroutine.running()
if is_async then if is_async then
init() init()
else else