Skip to content

Commit

Permalink
collect used response, see cloudwu#800
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwu committed Feb 4, 2018
1 parent 084aab4 commit 6cdc1cf
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
19 changes: 19 additions & 0 deletions lualib/skynet/datasheet/builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,24 @@ local function releasehandle(handle)
end
end

local function register_collector(name)
local function collect()
local m = dataset[name].monitor
local i = 1
while m[i] do
if not m[i] "TEST" then
local n = #m
m[i] = m[n]
m[n] = nil
else
i = i + 1
end
end
skynet.timeout(10 * 60 * 100, collect) -- 10 mins
end
collect()
end

-- from builder, create or update handle
function datasheet.update(name, handle)
local t = dataset[name]
Expand All @@ -88,6 +106,7 @@ function datasheet.update(name, handle)
t = { handle = handle, monitor = {} }
dataset[name] = t
handles[handle] = { ref = 1, name = name }
register_collector(name)
else
t.handle = handle
-- report update to customers
Expand Down
24 changes: 22 additions & 2 deletions test/testdatasheet.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local skynet = require "skynet"
local builder = require "skynet.datasheet.builder"
local datasheet = require "skynet.datasheet"

local mode = ...

local function dump(t, prefix)
for k,v in pairs(t) do
Expand All @@ -11,8 +11,26 @@ local function dump(t, prefix)
end
end

if mode == "child" then

local datasheet = require "skynet.datasheet"

skynet.start(function()
local t = datasheet.query("foobar")
dump(t, "[CHILD]")

skynet.sleep(100)
skynet.exit()
end)

else

local builder = require "skynet.datasheet.builder"
local datasheet = require "skynet.datasheet"

skynet.start(function()
builder.new("foobar", {a = 1, b = 2 , c = {3} })
skynet.newservice(SERVICE_NAME, "child")
local t = datasheet.query "foobar"
local c = t.c
dump(t, "[1]")
Expand All @@ -26,3 +44,5 @@ skynet.start(function()
skynet.sleep(100)
dump(t, "[3]")
end)

end

0 comments on commit 6cdc1cf

Please sign in to comment.