Skip to content

Commit ed2f23e

Browse files
committed
async:wait() can raise error
1 parent 9e1138c commit ed2f23e

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

lualib/service.lua

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,12 +400,18 @@ do -- async object
400400

401401
function ltask.async()
402402
local obj
403+
local function try_raise_error(type, msg, sz)
404+
local err = ltask.unpack_remove(msg, sz)
405+
if type == MESSAGE_ERROR then
406+
obj._err = err
407+
end
408+
end
403409
local function wait_func(type, session, msg, sz)
404410
-- ignore type
405-
ltask.unpack_remove(msg, sz)
411+
try_raise_error(type, msg, sz)
406412
while still_session(obj, session) do
407413
type, session, msg, sz = yield_session()
408-
ltask.unpack_remove(msg, sz)
414+
try_raise_error(type, msg, sz)
409415
end
410416

411417
if obj._wakeup then
@@ -435,6 +441,11 @@ do -- async object
435441
ltask.wait(self)
436442
end
437443
end
444+
local err = self._err
445+
if err ~= nil then
446+
self._err = nil
447+
rethrow_error(2, err)
448+
end
438449
self._wakeup = nil
439450
end
440451
end

0 commit comments

Comments
 (0)