Skip to content

Commit

Permalink
support AsynCall.
Browse files Browse the repository at this point in the history
  • Loading branch information
name5566 committed Jul 25, 2016
1 parent 46b14c8 commit 76c6dc4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions chanrpc/chanrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,7 @@ func (c *Client) Close() {
c.Cb(<-c.ChanAsynRet)
}
}

func (c *Client) Idle() bool {
return c.pendingAsynCall == 0
}
4 changes: 4 additions & 0 deletions go/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ func (g *Go) Close() {
}
}

func (g *Go) Idle() bool {
return g.pendingGo == 0
}

func (g *Go) NewLinearContext() *LinearContext {
c := new(LinearContext)
c.g = g
Expand Down
22 changes: 21 additions & 1 deletion module/skeleton.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import (
type Skeleton struct {
GoLen int
TimerDispatcherLen int
AsynCallLen int
ChanRPCServer *chanrpc.Server
g *g.Go
dispatcher *timer.Dispatcher
client *chanrpc.Client
server *chanrpc.Server
commandServer *chanrpc.Server
}
Expand All @@ -25,9 +27,13 @@ func (s *Skeleton) Init() {
if s.TimerDispatcherLen <= 0 {
s.TimerDispatcherLen = 0
}
if s.AsynCallLen <= 0 {
s.AsynCallLen = 0
}

s.g = g.New(s.GoLen)
s.dispatcher = timer.NewDispatcher(s.TimerDispatcherLen)
s.client = chanrpc.NewClient(s.AsynCallLen)
s.server = s.ChanRPCServer

if s.server == nil {
Expand All @@ -42,8 +48,13 @@ func (s *Skeleton) Run(closeSig chan bool) {
case <-closeSig:
s.commandServer.Close()
s.server.Close()
s.g.Close()
for !s.g.Idle() || !s.client.Idle() {
s.g.Close()
s.client.Close()
}
return
case ri := <-s.client.ChanAsynRet:
s.client.Cb(ri)
case ci := <-s.server.ChanCall:
s.server.Exec(ci)
case ci := <-s.commandServer.ChanCall:
Expand Down Expand Up @@ -88,6 +99,15 @@ func (s *Skeleton) NewLinearContext() *g.LinearContext {
return s.g.NewLinearContext()
}

func (s *Skeleton) AsynCall(server *chanrpc.Server, id interface{}, args ...interface{}) {
if s.AsynCallLen == 0 {
panic("invalid AsynCallLen")
}

s.client.Attach(server)
s.client.AsynCall(id, args...)
}

func (s *Skeleton) RegisterChanRPC(id interface{}, f interface{}) {
if s.ChanRPCServer == nil {
panic("invalid ChanRPCServer")
Expand Down

0 comments on commit 76c6dc4

Please sign in to comment.