Here is what I was looking for. Maybe it helps someone in the future. Note the use of the select and c channel to combine it with the output channel
ln, err := net.Listen("tcp", ":8080") if err != nil { // handle error } defer ln.Close() for { type accepted struct { conn net.Conn err error } c := make(chan accepted, 1) go func() { conn, err := ln.Accept() c <- accepted{conn, err} }() select { case a := <-c: if a.err != nil { // handle error continue } go handleConnection(a.conn) case e := <-ev: // handle event return } }
mhstnsc
source share