eaburns/Watch

Fix clumsy race in run/kill

eaburns opened this issue · 2 comments

In retrospect, this is obviously fixed by using a channel:
Run selects between the kill channel and a default case with a non-blocking wait. If it gets kill once, SIGTERM; twice, SIGKILL (there you go, Steve) and nil the kill channel to stop this case. When killed, Wait will fire. No more race. No need for global pid, no "lock vomit." But we will need the shared channel.

The kill function should just do a non-blocking send on the kill channel. If run is selecting on it, great! If not, nothing's running and it's just ignored. Great!

👍