Skip to content

Commit

Permalink
fix(tasks): check if already cancelled
Browse files Browse the repository at this point in the history
See #15
  • Loading branch information
rcarriga committed May 1, 2024
1 parent 79e8968 commit e1b4c41
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lua/nio/tasks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ local format_error = function(message, traceback)
return string.format(
"The coroutine failed with this message: %s\n%s",
type(message) == "string" and vim.startswith(traceback, message) and ""
or ("\n" .. tostring(message)),
or ("\n" .. tostring(message)),
traceback
)
end
Expand All @@ -69,13 +69,13 @@ function nio.tasks.run(func, cb)
local future = require("nio").control.future()

function task.cancel()
if coroutine.status(co) == "dead" then
if cancelled or coroutine.status(co) == "dead" then
return
end
cancelled = true
for _, child in pairs(child_tasks[task] or {}) do
child.cancel()
end
cancelled = true
step()
end

Expand Down

0 comments on commit e1b4c41

Please sign in to comment.