From 8765cbc4d0c629c8158a5341e1b4305fd93c3a90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B3n=C3=A1n=20Carrigan?= Date: Thu, 2 May 2024 16:37:47 +0100 Subject: [PATCH] fix(tasks): gracefully handle callbacks after cancel If a callback returns after a task is already cancelled, we should gracefully handle it by not attempting to set the result of the task since it is already set. See #15 --- lua/nio/tasks.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lua/nio/tasks.lua b/lua/nio/tasks.lua index 58660c2..4bb2cc6 100644 --- a/lua/nio/tasks.lua +++ b/lua/nio/tasks.lua @@ -88,6 +88,9 @@ function nio.tasks.run(func, cb) end local function close_task(result, err) + if not tasks[co] then + return + end tasks[co] = nil if err then future.set_error(err)