added adhoc example

This commit is contained in:
Jian Han 2018-05-02 22:44:03 +10:00
parent 617693de02
commit 5c79e57262
2 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,27 @@
package main
import "fmt"
// Confinement is the simple yet powerful idea of ensuring information is only ever
// available from one concurrent process.
// When this is achieved, a concurrent program
//is implicitly safe and no synchronization is needed.
// Ad hoc confinement is when you achieve confinement through a convention—
// whether it be set by the languages community, the group you work within, or the
// codebase you work within
func main() {
data := make([]int, 4)
loopData := func(handleData chan<- int) {
defer close(handleData)
for i := range data {
handleData <- data[i]
}
}
handleData := make(chan int)
go loopData(handleData)
for num := range handleData {
fmt.Println(num)
}
}

View File

@ -107,6 +107,8 @@ func v2() {
"https://insights.stackoverflow.com/survey/2017", "https://insights.stackoverflow.com/survey/2017",
"https://hackernoon.com/top-10-python-web-frameworks-to-learn-in-2018-b2ebab969d1a", "https://hackernoon.com/top-10-python-web-frameworks-to-learn-in-2018-b2ebab969d1a",
"https://blog.kowalczyk.info/article/1Bkr/3-ways-to-iterate-in-go.html", "https://blog.kowalczyk.info/article/1Bkr/3-ways-to-iterate-in-go.html",
"A",
"B",
} }
for result := range checkStatus(done, urls...) { for result := range checkStatus(done, urls...) {
if result.Error != nil { if result.Error != nil {