News for hackers. Stuff that matters.
Re:Introduction to Go 1.1 by JulianMorrison on Thursday March 28, 2013 @07:47AM (#5454268)
Defer 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")
  }

There are no comments on this comment yet.