Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

tweaks on gen_server package: renamed types which should be private (…

…control messages/channel)
  • Loading branch information...
commit a596536423bf44359026903f946859ff8d9a48ee 1 parent 5cbf57a
@rpl authored
Showing with 12 additions and 12 deletions.
  1. +7 −7 pkg/gen_server/methods.go
  2. +5 −5 pkg/gen_server/types.go
View
14 pkg/gen_server/methods.go
@@ -22,9 +22,9 @@ func (self *GenServer) loop() {
case cmd := <- self.control_ch :
self.status = BUSY
switch ccmd := cmd.(type) {
- case InitControlMessage:
+ case initControlMessage:
self.handle_init(&ccmd)
- case StopControlMessage:
+ case stopControlMessage:
self.handle_stop(&ccmd)
}
}
@@ -44,14 +44,14 @@ func (self *GenServer) SetDebug(debug bool) {
}
// handle_init will be called to handle incoming InitControlMessages
-func (self *GenServer) handle_init(cmd *InitControlMessage) {
+func (self *GenServer) handle_init(cmd *initControlMessage) {
self.log("RECEIVED INIT ",cmd)
self.status = READY
cmd.ReplyChannel <- ReplyMessage{Ok: true}
}
// handle_stop will be called to handle incoming StopControlMessages
-func (self *GenServer) handle_stop(cmd *StopControlMessage) {
+func (self *GenServer) handle_stop(cmd *stopControlMessage) {
defer func() {
// TODO: error handling
self.status = STOPPED
@@ -82,19 +82,19 @@ func (self *GenServer) GetStatus() int {
func (self *GenServer) Start(impl IGenServerImpl) {
self.status = STARTING;
ch := make(MessageChannel)
- control_ch := make(ControlChannel)
+ control_ch := make(controlChannel)
self.ch = ch
self.control_ch = control_ch
self.impl = impl
go self.loop()
reply_ch := make(ReplyMessageChannel)
- self.control_ch <- InitControlMessage{ReplyChannel: reply_ch}
+ self.control_ch <- initControlMessage{ReplyChannel: reply_ch}
<- reply_ch
}
func (self *GenServer) Stop() ReplyMessage {
reply_ch := make(ReplyMessageChannel)
- self.control_ch <- StopControlMessage{ReplyChannel: reply_ch}
+ self.control_ch <- stopControlMessage{ReplyChannel: reply_ch}
return <- reply_ch
}
View
10 pkg/gen_server/types.go
@@ -26,21 +26,21 @@ type ReplyMessage struct {
// ControlMessage is a control message (optionally waits for a reply
// on the ReplyChannel)
-type ControlMessage interface {}
+type controlMessage interface {}
-type InitControlMessage struct {
+type initControlMessage struct {
Args Data
ReplyChannel ReplyMessageChannel
}
-type StopControlMessage struct {
+type stopControlMessage struct {
Args Data
ReplyChannel ReplyMessageChannel
}
// MessageChannel is the channel of the messages sent from a client to the gen_server
type MessageChannel chan Message
-type ControlChannel chan ControlMessage
+type controlChannel chan controlMessage
type ReplyMessageChannel chan ReplyMessage
// GenServer statuses
@@ -55,7 +55,7 @@ const (
// GenServer is the struct type of a GenServer, contains data needed by internal functions
type GenServer struct {
ch MessageChannel
- control_ch ControlChannel
+ control_ch controlChannel
impl IGenServerImpl
state Data
status int
Please sign in to comment.
Something went wrong with that request. Please try again.