Files
skynet/test/testselect.lua
云风 eaa60ca8dd Update to lua 5.4 (#1174)
* update to lua 5.4.0-rc1

* remove LUA_ERRGCMM

* use age bits for shared

* remove unused lbitlib.c

* use luaV_fastget

* fix #1174

* suspend函数tailcall优化

* 防止没有session导致未调用suspend

* luaH_setint check shared (#1184)

* set LUA_GCGEN by default

* fix #1174 (#1186)

checkshared in sweeplist

* update to lua 5.4 rc2

* update to lua 5.4 rc4

* move skynet.profile into snlua

* Use lua_sethook to interrupt tight loops

* remove lua_checksig

* critical condition for signals

* update to lua 5.4 released

* lua 5.4 bugfix

* update lua bugfix

* fix lua_sharestring (#1224)

* update lua

* update lua 5.4

* update README

* add skynet.select

* add test

* test error & discard

* yield session

* request error has no error message

* add timeout to skynet.select

* bugfix

* for lua 5.4

* new version

* bugfix

* bugfix

* use if instead of while

* make local

* yield in select for

* update lua 5.4.1

* change lua version (#1245)

Co-authored-by: xiaojin <xiaojin@onemt.com.cn>

* update lua version number

Co-authored-by: hong <hongling0@gmail.com>
Co-authored-by: hong <hongling-0@qq.com>
Co-authored-by: 风---自由 <996442717qqcom@gmail.com>
Co-authored-by: xiaojin <xiaojin@onemt.com.cn>
2020-10-10 13:36:59 +08:00

95 lines
1.8 KiB
Lua

local skynet = require "skynet"
local mode = ...
if mode == "slave" then
local COMMAND = {}
function COMMAND.ping(ti, str)
skynet.sleep(ti)
return str
end
function COMMAND.error()
error "ERROR"
end
function COMMAND.exit()
skynet.exit()
end
skynet.start(function()
skynet.dispatch("lua", function(_,_, cmd, ...)
skynet.ret(skynet.pack(COMMAND[cmd](...)))
end)
end)
else
local function info(fmt, ...)
skynet.error(string.format(fmt, ...))
end
skynet.start(function()
local slave = skynet.newservice(SERVICE_NAME, "slave")
for req, resp in skynet.request
{ slave, "lua", "ping", 6, "SLEEP 6" }
{ slave, "lua", "ping", 5, "SLEEP 5" }
{ slave, "lua", "ping", 4, "SLEEP 4" }
{ slave, "lua", "ping", 3, "SLEEP 3" }
{ slave, "lua", "ping", 2, "SLEEP 2" }
{ slave, "lua", "ping", 1, "SLEEP 1" }
:select() do
info("RESP %s", resp[1])
end
-- test timeout
local reqs = skynet.request()
for i = 1, 10 do
reqs:add { slave, "lua", "ping", i*10, "SLEEP " .. i, token = i }
end
for req, resp in reqs:select(50) do
info("RESP %s token<%s>", resp[1], req.token)
end
-- test error
for req, resp in skynet.request
{ slave, "lua", "error" }
{ slave, "lua", "ping", 0, "PING" }
: select() do
if resp then
info("Ping : %s", resp[1])
else
info("Error")
end
end
-- timeout call
local reqs = skynet.request { slave, "lua", "ping", 100 , "PING" }
for req, resp in reqs:select(10) do
info("%s", resp[1])
end
info("Timeout : %s", reqs.timeout)
-- call in select
for req, resp in skynet.request
{ slave, "lua", "ping", 20, "CALL 20" }
{ slave, "lua", "ping", 10, "CALL 10" }
: select() do
info("%s", skynet.call( slave, "lua", "ping", 0, "ping in " .. resp[1]) )
skynet.sleep(50)
end
skynet.send(slave, "lua", "exit")
skynet.exit()
end)
end