Lua: Add helpful error message if await is called without async

Change-Id: Idc0b381a31ebe81709906e182d9a932e7ec7142f
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Marcus Tillmanns
2024-05-08 13:28:44 +02:00
parent 3ead49ed33
commit f82a68221f

View File

@@ -69,10 +69,14 @@ local join = function(thunks)
end
-- sugar over coroutine
local await = function(defer)
local _, isMain = coroutine.running()
assert(not isMain, "a.wait was called outside of a running coroutine. You need to start one using a.sync(my_function)() first")
assert(type(defer) == "function", "type error :: expected func :: was: " .. type(defer))
return co.yield(defer)
end
local await_all = function(defer)
local _, isMain = coroutine.running()
assert(not isMain, "a.wait_all was called outside of a running coroutine. You need to start one using a.sync(my_function)() first")
assert(type(defer) == "table", "type error :: expected table")
return co.yield(join(defer))
end