mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-22 06:04:35 +00:00
[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:
parent
8c5fa157c7
commit
84197b5216
11
async.lua
11
async.lua
@ -12,7 +12,7 @@
|
||||
getting a reference to the task for manipulation
|
||||
attaching multiple callbacks
|
||||
cancelling
|
||||
` proper error traces with internal xpcall?
|
||||
` proper error traces for coroutines with async:add, additional wrapper?
|
||||
]]
|
||||
|
||||
local path = (...):gsub("async", "")
|
||||
@ -29,7 +29,14 @@ end
|
||||
|
||||
--add a task to the kernel
|
||||
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
|
||||
|
||||
--add an already-existing coroutine to the kernel
|
||||
|
Loading…
Reference in New Issue
Block a user