Skip to content

Commit b4d580a

Browse files
author
gbbr
committed
Fixed channel closure deadlock
1 parent 6a9fdef commit b4d580a

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

‎chapter7/patterns/pool/pool.go‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,16 @@ func (p *pool) Close() {
106106
return
107107
}
108108

109+
// TODO: Explain why flag needs to be off before calling CLose() on each
110+
// resource
111+
112+
// Toggle the flag
113+
p.closed = true
114+
// Close the channel
115+
close(p.resources)
116+
109117
// Close the resources
110118
for r := range p.resources {
111119
r.Close()
112120
}
113-
// Close the channel
114-
close(p.resources)
115-
// Toggle the flag
116-
p.closed = true
117121
}

0 commit comments

Comments
 (0)