mirror of
https://github.com/crazybber/awesome-patterns.git
synced 2024-11-26 06:46:07 +03:00
added adhoc example
This commit is contained in:
parent
617693de02
commit
5c79e57262
27
concurrency/confinement/adhoc/main.go
Normal file
27
concurrency/confinement/adhoc/main.go
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user