package xmpp import ( "time" "log" ) type Session struct { in, Out chan Event } func NewSession(jid string, pwd string) *Session { s := Session{} s.in = make(chan Event) s.Out = make(chan Event) return &s } func (s *Session) Run() { defer func() { s.Out <- DisconnectEvent }() s.init() for { select { case ev := <-s.in: switch ev { case ShouldDisconnectEvent: return default: log.Printf("Unknown Event '%d'!\n", ev) } } } } func (s *Session) init() { time.Sleep(time.Second) s.Out <- ConnectEvent } func (s *Session) Close() { go func(){ s.in <- ShouldDisconnectEvent }() }