It is common practice to provide time-out channels for reading and writing. This is a guarantee that ensures that goroutine will stop blocking if a given time interval is passed.
- , N http-. , , . HTTP , .
. Go playground. ,
, , . .
package main
import (
"fmt"
"time"
)
func main() {
queue := make(chan int, 1)
defer close(queue)
go func() {
select {
case val := <-queue:
fmt.Printf("Received: %d\n", val)
case <-time.After(3 * time.Second):
fmt.Println("Timeout!")
}
}()
<-time.After(5 * time.Second)
queue <- 123
}