buffer channels for better gc semantics
This commit is contained in:
parent
9e4622b63e
commit
fde2f767d1
@ -13,7 +13,7 @@ func main() {
|
||||
// For our example, suppose we're executing an external
|
||||
// call that returns its result on a channel `c1`
|
||||
// after 2s.
|
||||
c1 := make(chan string)
|
||||
c1 := make(chan string, 1)
|
||||
go func() {
|
||||
time.Sleep(time.Second * 2)
|
||||
c1 <- "result 1"
|
||||
@ -34,7 +34,7 @@ func main() {
|
||||
|
||||
// If we allow a longer timeout of 3s, then the receive
|
||||
// from `c2` will succeed and we'll print the result.
|
||||
c2 := make(chan string)
|
||||
c2 := make(chan string, 1)
|
||||
go func() {
|
||||
time.Sleep(time.Second * 2)
|
||||
c2 <- "result 2"
|
||||
|
Loading…
x
Reference in New Issue
Block a user