4 ms·
> "Let It Crash" (and handle the crash) panic() and recover() does that. It's not exceptions, but it does exactly that.
by nolok 13y ago
> "Let It Crash" (and handle the crash)
panic() and recover() does that. It's not exceptions, but it does exactly that.
- lazyjones 13y agoIt's the supervisor trees that are missing and cannot currently be implemented though.
- AeroNotix 13y agoAs a built-in language feature they are missing, but you can and some codebases do implement a kill channel for child goroutines.
- jerf 13y agoAs it happens, I've spent the last two days implementing supervision trees for Go, as I'm looking to port some stuff out of Erlang into Go. (There are a couple of existing libraries out there, but they are pretty weak tea, no offense to the authors in question, one of which is kind enough to label their effort with "this is my first Go code".) You can't implement Erlang-style trees without loss, and it's tricky due to some other things, but it can be done and you do get a substantial portion of the benefits, but also certainly not all. When I pop it up on github here soon, I'm planning on accompanying it by a blog post that will probably end up being longer than the entire library (including test suite and documentation) discussing all the whats and whys of how much you can and can not bring over of Erlang's approach.
- JulianMorrison 13y agoCan be, easily. Your goroutine defers a function that calls recover and notifies the supervisor if it was panicking. It's exactly what Erlang does, just done slightly more manually.
- dragonwriter 13y ago> It's the supervisor trees that are missing and cannot currently be implemented though. On a language level the support seems to be there, and not radically different from what Erlang offers. The pre-built libraries that make up OTP for Erlang aren't there and you have to build your own, but the underlying structure seems to be there.