Skip to content

Commit

Permalink
add testresponse
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwu committed Sep 1, 2014
1 parent 165bed4 commit 8b7ba7b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v0.6.2 (2014-9-1)
-----------
* bugfix: only skynet.call response PTYPE_ERROR

v0.6.1 (2014-8-25)
-----------
* bugfix: datacenter.wakeup
Expand Down
44 changes: 44 additions & 0 deletions test/testresponse.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
local skynet = require "skynet"

local mode = ...

if mode == "TICK" then
-- this service whould response the request every 1s.

local response_queue = {}

local function response()
while true do
skynet.sleep(100) -- sleep 1s
for k,v in ipairs(response_queue) do
v(true, skynet.now()) -- true means succ, false means error
response_queue[k] = nil
end
end
end

skynet.start(function()
skynet.fork(response)
skynet.dispatch("lua", function()
table.insert(response_queue, skynet.response())
end)
end)

else

local function request(tick, i)
print(i, "call", skynet.now())
print(i, "response", skynet.call(tick, "lua"))
print(i, "end", skynet.now())
end

skynet.start(function()
local tick = skynet.newservice(SERVICE_NAME, "TICK")

for i=1,5 do
skynet.fork(request, tick, i)
skynet.sleep(10)
end
end)

end

0 comments on commit 8b7ba7b

Please sign in to comment.