Skip to content

Commit 0184019

Browse files
committed
short chanrpc calls
1 parent bdf2f7d commit 0184019

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

chanrpc/chanrpc.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,27 @@ func (s *Server) Go(id interface{}, args ...interface{}) {
149149
}
150150
}
151151

152+
// goroutine safe
153+
func (s *Server) Call0(id interface{}, args ...interface{}) error {
154+
c := NewClient(0)
155+
c.Attach(s)
156+
return c.Call0(id, args...)
157+
}
158+
159+
// goroutine safe
160+
func (s *Server) Call1(id interface{}, args ...interface{}) (interface{}, error) {
161+
c := NewClient(0)
162+
c.Attach(s)
163+
return c.Call1(id, args...)
164+
}
165+
166+
// goroutine safe
167+
func (s *Server) CallN(id interface{}, args ...interface{}) ([]interface{}, error) {
168+
c := NewClient(0)
169+
c.Attach(s)
170+
return c.CallN(id, args...)
171+
}
172+
152173
func (s *Server) Close() {
153174
close(s.ChanCall)
154175

@@ -159,13 +180,6 @@ func (s *Server) Close() {
159180
}
160181
}
161182

162-
// goroutine safe
163-
func (s *Server) Open(l int) *Client {
164-
c := NewClient(l)
165-
c.Attach(s)
166-
return c
167-
}
168-
169183
func NewClient(l int) *Client {
170184
c := new(Client)
171185
c.chanSyncRet = make(chan *RetInfo, 1)

console/command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (c *ExternalCommand) run(_args []string) string {
4646
args[i] = v
4747
}
4848

49-
ret, err := c.server.Open(0).Call1(c._name, args...)
49+
ret, err := c.server.Call1(c._name, args...)
5050
if err != nil {
5151
return err.Error()
5252
}

gate/gate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (a *agent) Run() {
109109

110110
func (a *agent) OnClose() {
111111
if a.gate.AgentChanRPC != nil {
112-
err := a.gate.AgentChanRPC.Open(0).Call0("CloseAgent", a)
112+
err := a.gate.AgentChanRPC.Call0("CloseAgent", a)
113113
if err != nil {
114114
log.Error("chanrpc error: %v", err)
115115
}

0 commit comments

Comments
 (0)