// methodChild loops until the handle method signals termination. func methodChild(h *supervisor.Handle, s *starts) error { s.incr(h) for !h.IsTerminated() { time.Sleep(10 * time.Millisecond) } return nil }
// errorChild returns an error after a given time. func errorChild(h *supervisor.Handle, s *starts, t time.Duration) error { s.incr(h) select { case <-h.Terminate(): return nil case <-time.After(t): return fmt.Errorf("error!") } return nil }
// panicChild produces a panic after a given time. func panicChild(h *supervisor.Handle, s *starts, t time.Duration) error { s.incr(h) select { case <-h.Terminate(): return nil case <-time.After(t): panic("panic!") } return nil }
// selectChild works in a select loop until terminated. func selectChild(h *supervisor.Handle, s *starts) error { s.incr(h) for { select { case <-h.Terminate(): return nil case <-time.After(10 * time.Millisecond): } } return nil }
func (s *starts) incr(h *supervisor.Handle) { s.mutex.Lock() defer s.mutex.Unlock() id := h.Id() s.counter[id]++ }