Skip to content

Commit e44a9b8

Browse files
More idiomatic way to check closed channel.
1 parent 60500ca commit e44a9b8

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

chapter6/example10/example10.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,9 @@ func worker(tasks chan string, worker int) {
5757

5858
for {
5959
// Wait for work to be assigned.
60-
task := <-tasks
61-
62-
// If we get the default value for a string the
63-
// channel was closed so quit.
64-
if task == "" {
60+
task, ok := <-tasks
61+
if !ok {
62+
// This means the channel is empty and closed.
6563
fmt.Printf("Worker: %d : Shutting Down\n", worker)
6664
return
6765
}

0 commit comments

Comments
 (0)