fix(frontends/lua): make sure Lua 'sleep' function support interruption
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
3a93212d5e
commit
0934d7b2f4
2 changed files with 12 additions and 2 deletions
|
@ -549,8 +549,7 @@ static int check_interrupted(lua_State *) { // NOLINT
|
|||
}
|
||||
|
||||
static int sleep(lua_State * L) {
|
||||
std::chrono::milliseconds dura(luaL_checkinteger(L, 1));
|
||||
std::this_thread::sleep_for(dura);
|
||||
sleep_for(luaL_checkinteger(L, 1));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
11
tests/lua/threads/sleep1.lua
Normal file
11
tests/lua/threads/sleep1.lua
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
S = State()
|
||||
T = thread(S, [[
|
||||
sleep(10000)
|
||||
]])
|
||||
|
||||
T:interrupt()
|
||||
local ok, msg = pcall(function() T:wait() end)
|
||||
assert(not ok)
|
||||
assert(is_exception(msg))
|
||||
assert(msg:what() == "interrupted")
|
Loading…
Add table
Reference in a new issue