nareix / joy4

Golang audio/video library and streaming server
MIT License
2.67k stars 499 forks source link

Add listener close function #106

Open dmorn opened 4 years ago

dmorn commented 4 years ago

Close #26.

I'm doing graceful shutdowns by wrapping the RTMP server and adding context to the ListenAndServe function

func (s *Server) ListenAndServe(ctx context.Context) error {
    go func() {
        <-ctx.Done()
        s.rtmps.Close()
    }()
    return s.rtmps.ListenAndServe()
}

When the context is canceled, ListenAndServe will stop blocking.