-
Notifications
You must be signed in to change notification settings - Fork 41
Open
Description
hi, i would like to understand the rationale of this block of code.
func (t *Tomb) run(f func() error) {
err := f()
t.m.Lock()
defer t.m.Unlock()
t.alive--
if t.alive == 0 || err != nil {
t.kill(err)
if t.alive == 0 {
close(t.dead)
}
}
}
i am fitting Tomb into a long running service where goroutines are started and completed. the Tomb will kill itself after the last goroutine finishes while the service is still running and will still launch more goroutines. what is the expected usage of Tomb in this case? what will happen if the code is changed to
func (t *Tomb) run(f func() error) {
err := f()
t.m.Lock()
defer t.m.Unlock()
t.alive--
if err != nil {
t.kill(err)
if t.alive == 0 {
close(t.dead)
}
return
}
if t.alive == 0 {
select {
default:
return
case <-t.dying:
close(t.dead)
}
}
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels