You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
typeJobstruct {
tomb*tomb.Tomb
}
func (j*Job) Start() error {
ifj.tomb.Alive() {
returnerrors.New("job is still running")
}
j.tomb=&tomb.Tomb{}
j.tomb.Go()
}
I want to create service that has long running goroutine, but only one, above code is not safe because Alive() can return false when tomb is in Dying state. So, I would like to know if tomb is Running (so dying or alive) or not. And there doesn't seem to be a way to actually do this with tomb.
I could read Dead() chan, but this would work only when tomb died, but if it never was started then it would hang forever as it is initialized as open chan.
Terminating() would be also useful since we don't always wait on channels in goroutines, but this can be easily done even without modifications to tomb.
Consider below pseudo code
I want to create service that has long running goroutine, but only one, above code is not safe because
Alive()
can returnfalse
when tomb is in Dying state. So, I would like to know if tomb is Running (so dying or alive) or not. And there doesn't seem to be a way to actually do this with tomb.I could read
Dead()
chan, but this would work only when tomb died, but if it never was started then it would hang forever as it is initialized as open chan.Easy way would be something like this:
Terminating()
would be also useful since we don't always wait on channels in goroutines, but this can be easily done even without modifications to tomb.The text was updated successfully, but these errors were encountered: