From 6e1fffac9a0873e0c28b7e3fe65ff7d8f9f06217 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E9=A3=8E?= Date: Tue, 28 Aug 2012 13:11:03 +0800 Subject: [PATCH] change skynet.timeout api --- lualib/skynet.lua | 17 ++++++----------- service/testtimer.lua | 2 +- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/lualib/skynet.lua b/lualib/skynet.lua index 6bc0e164..82ae2b92 100644 --- a/lualib/skynet.lua +++ b/lualib/skynet.lua @@ -53,25 +53,20 @@ function suspend(co, result, command, param, size) dispatch_wakeup() end -function skynet.timeout(ti, func, ...) +function skynet.timeout(ti, func) local session = c.command("TIMEOUT",tostring(ti)) assert(session) session = tonumber(session) - local co - if select("#",...) == 0 then - co = coroutine.create(func) - else - local args = { ... } - co = coroutine.create(function() - func(unpack(args)) - end) - end + local co = coroutine.create(func) assert(session_id_coroutine[session] == nil) session_id_coroutine[session] = co end function skynet.fork(func,...) - skynet.timeout("0", func, ...) + local args = { ... } + skynet.timeout("0", function() + func(unpack(args)) + end) end function skynet.sleep(ti) diff --git a/service/testtimer.lua b/service/testtimer.lua index b98cd6f6..6b6a3a55 100644 --- a/service/testtimer.lua +++ b/service/testtimer.lua @@ -16,7 +16,7 @@ end skynet.start(function() skynet.fork(wakeup, coroutine.running()) - skynet.timeout(300, timeout, "Hello World") + skynet.timeout(300, function() timeout "Hello World" end) for i = 1, 10 do print(i, skynet.now()) print(skynet.sleep(100))