Skip to content

Commit

Permalink
Use a defer in Kill, as suggested by Frank.
Browse files Browse the repository at this point in the history
  • Loading branch information
niemeyer committed Apr 3, 2012
1 parent b31da7c commit b44f4aa
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions tomb.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,9 @@ func (t *Tomb) Done() {
func (t *Tomb) Kill(reason error) {
t.init()
t.m.Lock()
defer t.m.Unlock()
if reason == ErrDying {
alive := t.reason == ErrStillAlive
t.m.Unlock()
if alive {
if t.reason == ErrStillAlive {
panic("tomb: Kill with ErrDying while still alive")
}
return
Expand All @@ -145,7 +144,6 @@ func (t *Tomb) Kill(reason error) {
default:
close(t.dying)
}
t.m.Unlock()
}

// Killf works like Kill, but builds the reason providing the received
Expand Down

0 comments on commit b44f4aa

Please sign in to comment.