document the usage of errCh

This commit is contained in:
Haowei Cai 2019-03-28 16:55:03 -07:00
parent 094938895a
commit 5809b6a428

View File

@ -92,7 +92,8 @@ func (t *timeoutHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
errCh := make(chan interface{})
// resultCh is used as both errCh and stopCh
resultCh := make(chan interface{})
tw := newTimeoutWriter(w)
go func() {
defer func() {
@ -103,12 +104,13 @@ func (t *timeoutHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
buf = buf[:runtime.Stack(buf, false)]
err = fmt.Sprintf("%v\n%s", err, buf)
}
errCh <- err
resultCh <- err
}()
t.handler.ServeHTTP(tw, r)
}()
select {
case err := <-errCh:
case err := <-resultCh:
// panic if error occurs; stop otherwise
if err != nil {
panic(err)
}