forked from qt-creator/qt-creator
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:
@@ -69,10 +69,14 @@ local join = function(thunks)
|
|||||||
end
|
end
|
||||||
-- sugar over coroutine
|
-- sugar over coroutine
|
||||||
local await = function(defer)
|
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))
|
assert(type(defer) == "function", "type error :: expected func :: was: " .. type(defer))
|
||||||
return co.yield(defer)
|
return co.yield(defer)
|
||||||
end
|
end
|
||||||
local await_all = function(defer)
|
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")
|
assert(type(defer) == "table", "type error :: expected table")
|
||||||
return co.yield(join(defer))
|
return co.yield(join(defer))
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user