diff options
author | Marcus Tillmanns <marcus.tillmanns@qt.io> | 2024-05-08 13:28:44 +0200 |
---|---|---|
committer | Marcus Tillmanns <marcus.tillmanns@qt.io> | 2024-05-08 11:37:11 +0000 |
commit | f82a68221fd36ffc183abb9dc898dbcda47ebd55 (patch) | |
tree | dd5d86f8fdabdaeb3e1f95c013e40d1ae8fef568 | |
parent | 3ead49ed33132d52d7aff6bb156a9cdf6a3f131c (diff) |
Lua: Add helpful error message if await is called without async
Change-Id: Idc0b381a31ebe81709906e182d9a932e7ec7142f
Reviewed-by: David Schulz <david.schulz@qt.io>
-rw-r--r-- | src/plugins/lua/bindings/async.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/plugins/lua/bindings/async.cpp b/src/plugins/lua/bindings/async.cpp index 31b3cbcd36..8d7d4f4750 100644 --- a/src/plugins/lua/bindings/async.cpp +++ b/src/plugins/lua/bindings/async.cpp @@ -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 |