[added] proper tracebacks to errors in async tasks with xpcall (only works for functions with :call, not coroutines with :add)

This commit is contained in:
Max Cahill 2020-07-24 09:15:28 +10:00
parent 8c5fa157c7
commit 84197b5216

View File

@ -12,7 +12,7 @@
getting a reference to the task for manipulation getting a reference to the task for manipulation
attaching multiple callbacks attaching multiple callbacks
cancelling cancelling
` proper error traces with internal xpcall? ` proper error traces for coroutines with async:add, additional wrapper?
]] ]]
local path = (...):gsub("async", "") local path = (...):gsub("async", "")
@ -29,7 +29,14 @@ end
--add a task to the kernel --add a task to the kernel
function async:call(f, args, callback, error_callback) function async:call(f, args, callback, error_callback)
self:add(coroutine.create(f), args, callback, error_callback) self:add(coroutine.create(function(...)
local results = {xpcall(f, debug.traceback, ...)}
local success = table.remove(results, 1)
if not success then
error(table.remove(results, 1))
end
return unpack(results)
end), args, callback, error_callback)
end end
--add an already-existing coroutine to the kernel --add an already-existing coroutine to the kernel