example of confinement

This commit is contained in:
Jian Han 2018-05-04 19:38:39 +10:00
parent 5c79e57262
commit f5bf6c88bb
2 changed files with 16 additions and 2 deletions

View File

@ -24,4 +24,20 @@ func main() {
for num := range handleData {
fmt.Println(num)
}
doWork := func(strings <-chan string) <-chan interface{} {
completed := make(chan interface{})
go func() {
defer fmt.Println("doWork exited.")
defer close(completed)
for s := range strings {
// Do something interesting
fmt.Println(s, "TTT")
}
}()
return completed
}
doWork(nil)
// Perhaps more work is done here
fmt.Println("Done.")
}

View File

@ -107,8 +107,6 @@ func v2() {
"https://insights.stackoverflow.com/survey/2017",
"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",
"A",
"B",
}
for result := range checkStatus(done, urls...) {
if result.Error != nil {