Skip to content

Instantly share code, notes, and snippets.

@logrusorgru
Created October 25, 2017 17:31
Show Gist options
  • Save logrusorgru/a1bb701c47df9ff565edb25e0763a141 to your computer and use it in GitHub Desktop.
Save logrusorgru/a1bb701c47df9ff565edb25e0763a141 to your computer and use it in GitHub Desktop.
is initialized
type MessengerFactory struct {
factory.MessengerFactory
isInitialized bool
}
func (m *MessengerFactory) IsInitialized() bool { return m.isInitialized }
func (m *MessengerFactory) Connect(address string) (conn *Connection, err error) {
return m.ConnectWithConfig(address, nil)
}
func (m *MessengerFactory) ConnectWithConfig(address string, config *ConnConfig) (conn *Connection, err error) {
if conn, err = m.MessengerFactory.ConnectWithConfig(address, config); err == nil {
m.isInitialized = true
}
return
}
func (m *MessengerFactory) Listen(address string) (err error) {
if err = m.MessengerFactory.Listen(address); err == nil {
m.isInitialized = true
}
return
}
func (m *MessengerFactory) ForEachConn(fn func(connection *Connection)) {
if m.isInitialized == false {
return
}
m.MessengerFactory.ForEachConn(fn)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment