Merge pull request #271 from mmcgrana/clarify-timeout-chan
Clarify use of buffered channel in the timeouts example.
This commit is contained in:
@@ -12,7 +12,10 @@ func main() {
|
||||
|
||||
// For our example, suppose we're executing an external
|
||||
// call that returns its result on a channel `c1`
|
||||
// after 2s.
|
||||
// after 2s. Note that the channel is buffered, so the
|
||||
// send in the goroutine is nonblocking. This is a
|
||||
// common pattern to prevent goroutine leaks in case the
|
||||
// channel is never read.
|
||||
c1 := make(chan string, 1)
|
||||
go func() {
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
93343e1aacb14f818c87732914c29ba57afab245
|
||||
MgcfA-xpJO9
|
||||
b1e8d0efbabd0c52271a85fad5ad58dcd1c7c476
|
||||
gyY_qDsRVUe
|
||||
|
||||
@@ -3,9 +3,3 @@
|
||||
$ go run timeouts.go
|
||||
timeout 1
|
||||
result 2
|
||||
|
||||
# Using this `select` timeout pattern requires
|
||||
# communicating results over channels. This is a good
|
||||
# idea in general because other important Go features are
|
||||
# based on channels and `select`. We'll look at two
|
||||
# examples of this next: timers and tickers.
|
||||
|
||||
Reference in New Issue
Block a user