2 ms·
Right now, as near as I can tell, you basically can't implement an Erlang supervision tree in Go. You don't have anything like linking, which really has to be g
by jerf 14y ago
Right now, as near as I can tell, you basically can't implement an Erlang supervision tree in Go. You don't have anything like linking, which really has to be guaranteed by the runtime to work properly at scale, so bodging something together with some 'defer' really doesn't cut it. You also can't talk about "a goroutine", because you can't get a reference or a handle to one (no such thing), you can only get channels, but they aren't guaranteed to map in any particular way to goroutines.
I've done Erlang for years and Go for weeks, so I'm trying to withhold judgement, but I still feel like Erlang got it more right here; it's way easier to restrict yourself to a subset of Erlang that looks like a channel if that is desirable for some reason than to implement process features with channels in Go.
- JulianMorrison 14y agoDefer and recover are guaranteed by the runtime, so deferring a recovery that launches a goroutine which sends a value on a child-died channel is not quite a bodge. However as you point out unlike Erlang there are no PIDs, so you'd either need a channel per child or an ID per child. And the whole thing would be very, very manual. Something like type Crash struct { PID int Panic interface{} } var crashed = make(chan Crash) func parent() { go child() oops := <-crashed panic(oops) } func child() { defer func() { if r := recover(); r != nil { crashed <- Crash{1, r} } } panic("boom") }