package xmpp import ( "log" "time" ) type SessionConnect struct{} type SessionDisconnect struct{} type SessionShouldDisconnect struct{} type Session struct { in, out chan any } func StartSession(out chan any, jid string, pwd string) chan any { s := Session{} s.in = make(chan any) s.out = out go s.run() return s.in } func (s *Session) run() { defer func() { s.out <- SessionDisconnect{} }() time.Sleep(time.Second) // faked connect time s.out <- SessionConnect{} for { select { case data := <-s.in: switch data.(type) { case SessionShouldDisconnect: return default: log.Printf("Unknown data '%d'!\n", data) } } } }