Last active
December 23, 2015 14:24
-
-
Save netmarkjp/7bc8c2c24139638f5685 to your computer and use it in GitHub Desktop.
Revisions
-
netmarkjp revised this gist
Dec 23, 2015 . 1 changed file with 6 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -34,11 +34,15 @@ func main() { } for { if len(task) == 0 { for i := 0; i < parallel; i++ { taskquit <- true } } time.Sleep(200 * time.Millisecond) } }() for i := 0; i < parallel; i++ { <-workerquit } } -
netmarkjp created this gist
Dec 23, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ package main import ( "fmt" "time" ) func main() { task := make(chan string) taskquit := make(chan bool) workerquit := make(chan bool) parallel := 3 for i := 0; i < parallel; i++ { go func() { loop: for { select { case <-taskquit: workerquit <- true break loop case job := <-task: fmt.Println(job) time.Sleep(1 * time.Second) } } }() } go func() { for n := 0; n < 7; n++ { task <- fmt.Sprintf("お仕事%03d", n+1) } for { if len(task) == 0 { taskquit <- true } time.Sleep(200 * time.Millisecond) } }() <-workerquit }