From e1b4c41df7257086e7744c675834e64584aa3cee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B3n=C3=A1n=20Carrigan?= Date: Wed, 1 May 2024 11:11:55 +0100 Subject: [PATCH] fix(tasks): check if already cancelled See #15 --- lua/nio/tasks.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lua/nio/tasks.lua b/lua/nio/tasks.lua index 7162b6f..f3898ec 100644 --- a/lua/nio/tasks.lua +++ b/lua/nio/tasks.lua @@ -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 @@ -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