forked from cloudwu/skynet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsharedata.lua
43 lines (34 loc) · 872 Bytes
/
sharedata.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
local skynet = require "skynet"
local sd = require "sharedata.corelib"
local service
skynet.init(function()
service = skynet.uniqueservice "sharedatad"
end)
local sharedata = {}
local function monitor(name, obj, cobj)
local newobj = cobj
while true do
newobj = skynet.call(service, "lua", "monitor", name, newobj)
if newobj == nil then
break
end
sd.update(obj, newobj)
end
end
function sharedata.query(name)
local obj = skynet.call(service, "lua", "query", name)
local r = sd.box(obj)
skynet.send(service, "lua", "confirm" , obj)
skynet.fork(monitor,name, r, obj)
return r
end
function sharedata.new(name, v)
skynet.call(service, "lua", "new", name, v)
end
function sharedata.update(name, v)
skynet.call(service, "lua", "update", name, v)
end
function sharedata.delete(name)
skynet.call(service, "lua", "delete", name)
end
return sharedata