diff options
author | Agniva De Sarker <agnivade@yahoo.co.in> | 2018-04-14 00:23:09 +0530 |
---|---|---|
committer | Andrew Bonventre <andybons@golang.org> | 2018-04-13 19:50:50 +0000 |
commit | 7edc962a942e4a9d5e06dde79299f7fc5605f000 (patch) | |
tree | d05d3cbb132e60ace21a28184833cc4b31ef59c3 /content/go-concurrency-patterns-timing-out-and.article | |
parent | efc7460c787535c46feadda9f7c395f16a615306 (diff) |
content: update all golang.org links to https
Ran sed -i 's/\[\[http:\/\/golang.org/\[\[https:\/\/golang.org/g' *.article
Change-Id: I88acc5104e1a3fc5e9a1cf11b600b657202d8997
Reviewed-on: https://go-review.googlesource.com/106955
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
Diffstat (limited to 'content/go-concurrency-patterns-timing-out-and.article')
-rw-r--r-- | content/go-concurrency-patterns-timing-out-and.article | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/content/go-concurrency-patterns-timing-out-and.article b/content/go-concurrency-patterns-timing-out-and.article index fa81a2c..93411fd 100644 --- a/content/go-concurrency-patterns-timing-out-and.article +++ b/content/go-concurrency-patterns-timing-out-and.article @@ -25,7 +25,7 @@ We can then use a `select` statement to receive from either `ch` or `timeout`. I The `timeout` channel is buffered with space for 1 value, allowing the timeout goroutine to send to the channel and then exit. The goroutine doesn't know (or care) whether the value is received. This means the goroutine won't hang around forever if the `ch` receive happens before the timeout is reached. The `timeout` channel will eventually be deallocated by the garbage collector. -(In this example we used `time.Sleep` to demonstrate the mechanics of goroutines and channels. In real programs you should use ` [[http://golang.org/pkg/time/#After][time.After]]`, a function that returns a channel and sends on that channel after the specified duration.) +(In this example we used `time.Sleep` to demonstrate the mechanics of goroutines and channels. In real programs you should use ` [[https://golang.org/pkg/time/#After][time.After]]`, a function that returns a channel and sends on that channel after the specified duration.) Let's look at another variation of this pattern. In this example we have a program that reads from multiple replicated databases simultaneously. The program needs only one of the answers, and it should accept the answer that arrives first. @@ -46,6 +46,6 @@ The function `Query` takes a slice of database connections and a `query` string. In this example, the closure does a non-blocking send, which it achieves by using the send operation in `select` statement with a `default` case. If the send cannot go through immediately the default case will be selected. Making the send non-blocking guarantees that none of the goroutines launched in the loop will hang around. However, if the result arrives before the main function has made it to the receive, the send could fail since no one is ready. -This problem is a textbook example of what is known as a [[https://en.wikipedia.org/wiki/Race_condition][race condition]], but the fix is trivial. We just make sure to buffer the channel `ch` (by adding the buffer length as the second argument to [[http://golang.org/pkg/builtin/#make][make]]), guaranteeing that the first send has a place to put the value. This ensures the send will always succeed, and the first value to arrive will be retrieved regardless of the order of execution. +This problem is a textbook example of what is known as a [[https://en.wikipedia.org/wiki/Race_condition][race condition]], but the fix is trivial. We just make sure to buffer the channel `ch` (by adding the buffer length as the second argument to [[https://golang.org/pkg/builtin/#make][make]]), guaranteeing that the first send has a place to put the value. This ensures the send will always succeed, and the first value to arrive will be retrieved regardless of the order of execution. These two examples demonstrate the simplicity with which Go can express complex interactions between goroutines. |