fix(picker.async): fixed aborting a coroutine from the coroutine itself. See #665
Some checks failed
CI / ci (push) Failing after 0s

This commit is contained in:
Folke Lemaitre 2025-01-21 12:52:36 +01:00
parent 66d2854ea0
commit c1e2c619b2
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
2 changed files with 4 additions and 2 deletions

View file

@ -69,7 +69,6 @@ function M:run(picker)
---@cast finder fun(cb:async fun(item:snacks.picker.finder.Item), task:snacks.picker.Async) ---@cast finder fun(cb:async fun(item:snacks.picker.finder.Item), task:snacks.picker.Async)
---@diagnostic disable-next-line: await-in-sync ---@diagnostic disable-next-line: await-in-sync
self.task = Async.new(function() self.task = Async.new(function()
local async = Async.running()
---@async ---@async
finder(function(item) finder(function(item)
if #self.items >= limit then if #self.items >= limit then
@ -83,7 +82,7 @@ function M:run(picker)
picker.matcher.task:resume() picker.matcher.task:resume()
yield = yield or Async.yielder(YIELD_FIND) yield = yield or Async.yielder(YIELD_FIND)
yield() yield()
end, async) end, self.task)
end):on("done", function() end):on("done", function()
collectgarbage("restart") collectgarbage("restart")
if not self.task:aborted() then if not self.task:aborted() then

View file

@ -186,6 +186,9 @@ function Async:abort()
return return
end end
self._aborted = true self._aborted = true
if coroutine.running() == self._co then
error("aborted", 2)
end
coroutine.resume(self._co, "abort") coroutine.resume(self._co, "abort")
end end