forked from cloudwu/skynet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestsm.lua
48 lines (42 loc) · 973 Bytes
/
testsm.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
44
45
46
47
48
local skynet = require "skynet"
local sharemap = require "skynet.sharemap"
local mode = ...
if mode == "slave" then
--slave
local function dump(reader)
reader:update()
print("x=", reader.x)
print("y=", reader.y)
print("s=", reader.s)
end
skynet.start(function()
local reader
skynet.dispatch("lua", function(_,_,cmd,...)
if cmd == "init" then
reader = sharemap.reader(...)
else
assert(cmd == "ping")
dump(reader)
end
skynet.ret()
end)
end)
else
-- master
skynet.start(function()
-- register share type schema
sharemap.register("./test/sharemap.sp")
local slave = skynet.newservice(SERVICE_NAME, "slave")
local writer = sharemap.writer("foobar", { x=0,y=0,s="hello" })
skynet.call(slave, "lua", "init", "foobar", writer:copy())
writer.x = 1
writer:commit()
skynet.call(slave, "lua", "ping")
writer.y = 2
writer:commit()
skynet.call(slave, "lua", "ping")
writer.s = "world"
writer:commit()
skynet.call(slave, "lua", "ping")
end)
end