From f5bf6c88bb035b49f2207c48b27c535865bf4b71 Mon Sep 17 00:00:00 2001 From: Jian Han Date: Fri, 4 May 2018 19:38:39 +1000 Subject: [PATCH] example of confinement --- concurrency/confinement/adhoc/main.go | 16 ++++++++++++++++ concurrency/iterator_error_handling/main.go | 2 -- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/concurrency/confinement/adhoc/main.go b/concurrency/confinement/adhoc/main.go index 8bb1ab6..e433578 100644 --- a/concurrency/confinement/adhoc/main.go +++ b/concurrency/confinement/adhoc/main.go @@ -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.") } diff --git a/concurrency/iterator_error_handling/main.go b/concurrency/iterator_error_handling/main.go index 32fc812..0057b06 100644 --- a/concurrency/iterator_error_handling/main.go +++ b/concurrency/iterator_error_handling/main.go @@ -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 {