Exemplo n.º 1
0
// 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
}
Exemplo n.º 2
0
// 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
}
Exemplo n.º 3
0
// 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
}
Exemplo n.º 4
0
// 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
}
Exemplo n.º 5
0
func (s *starts) incr(h *supervisor.Handle) {
	s.mutex.Lock()
	defer s.mutex.Unlock()
	id := h.Id()
	s.counter[id]++
}