mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-26 15:44:35 +00:00
[fixed] issued with async
This commit is contained in:
parent
22acd78e5e
commit
0a1e55b300
13
async.lua
13
async.lua
@ -18,7 +18,7 @@ function async:new()
|
|||||||
end
|
end
|
||||||
|
|
||||||
--add a task to the kernel
|
--add a task to the kernel
|
||||||
function async:run(f, args, cb, error_cb)
|
function async:call(f, args, cb, error_cb)
|
||||||
table.insert(self.tasks, {
|
table.insert(self.tasks, {
|
||||||
coroutine.create(f),
|
coroutine.create(f),
|
||||||
args,
|
args,
|
||||||
@ -36,7 +36,12 @@ function async:update()
|
|||||||
end
|
end
|
||||||
--run a step
|
--run a step
|
||||||
local co, args, cb, error_cb = td[1], td[2], td[3], td[4]
|
local co, args, cb, error_cb = td[1], td[2], td[3], td[4]
|
||||||
local success, a, b, c, d, e, f, g, h = coroutine.resume(co, unpack(args))
|
--(reuse these 8 temps)
|
||||||
|
local a, b, c, d, e, f, g, h
|
||||||
|
if args then
|
||||||
|
a, b, c, d, e, f, g, h = unpack(args)
|
||||||
|
end
|
||||||
|
local success, a, b, c, d, e, f, g, h = coroutine.resume(co, a, b, c, d, e, f, g, h)
|
||||||
--error?
|
--error?
|
||||||
if not success then
|
if not success then
|
||||||
if error_cb then
|
if error_cb then
|
||||||
@ -46,12 +51,12 @@ function async:update()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
--check done
|
--check done
|
||||||
if coroutine.status(task) == "dead" then
|
if coroutine.status(co) == "dead" then
|
||||||
--done? run callback with result
|
--done? run callback with result
|
||||||
cb(a, b, c, d, e, f, g, h)
|
cb(a, b, c, d, e, f, g, h)
|
||||||
else
|
else
|
||||||
--if not done, re-add
|
--if not done, re-add
|
||||||
table.insert(self.tasks, taskdef)
|
table.insert(self.tasks, td)
|
||||||
end
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
Loading…
Reference in New Issue
Block a user