func (sv *Supervisor) StartChild(supervisor Process, name string, args ...etf.Term) (Process, error) {
	message := messageStartChild{
		name: name,
		args: args,
	}
	value, err := supervisor.Direct(message)
	if err != nil {
		return nil, err
	}
	process, ok := value.(Process)
	if !ok {
		return nil, fmt.Errorf("internal error: can't start child %#v", value)
	}
	return process, nil
}
StartChild dynamically starts a child process with given name of child spec which is defined by Init call.
package gen
import (
	"fmt"
	"time"
	"github.com/ergo-services/ergo/etf"
	"github.com/ergo-services/ergo/lib"
)
type SupervisorBehavior interface {
	ProcessBehavior
	Init(args ...etf.Term) (SupervisorSpec, error)
}
type SupervisorStrategy struct {
	Type      SupervisorStrategyType
	Intensity uint16
	Period    uint16
	Restart   SupervisorStrategyRestart
}
type SupervisorStrategyType = string
type SupervisorStrategyRestart = string
const (
	SupervisorRestartIntensity = uint16(10)
	SupervisorRestartPeriod = uint16(10)
	SupervisorStrategyOneForOne = SupervisorStrategyType("one_for_one")
	SupervisorStrategyOneForAll = SupervisorStrategyType("one_for_all")
	SupervisorStrategyRestForOne = SupervisorStrategyType("rest_for_one")
	SupervisorStrategySimpleOneForOne = SupervisorStrategyType("simple_one_for_one")
	SupervisorStrategyRestartPermanent = SupervisorStrategyRestart("permanent")
	SupervisorStrategyRestartTemporary = SupervisorStrategyRestart("temporary")
	SupervisorStrategyRestartTransient = SupervisorStrategyRestart("transient")
	supervisorChildStateStart    = 0
	supervisorChildStateRunning  = 1
	supervisorChildStateDisabled = -1
)
type supervisorChildState int
type SupervisorSpec struct {
	Name     string
	Children []SupervisorChildSpec
	Strategy SupervisorStrategy
	restarts []int64
}
type SupervisorChildSpec struct {
	Node    string
	Name    string
	Child   ProcessBehavior
	Args    []etf.Term
	state   supervisorChildState  
	process Process
}
type Supervisor struct{}
type messageStartChild struct {
	name string
	args []etf.Term
}
func (sv *Supervisor) ProcessInit(p Process, args ...etf.Term) (ProcessState, error) {
	behavior, ok := p.Behavior().(SupervisorBehavior)
	if !ok {
		return ProcessState{}, fmt.Errorf("ProcessInit: not a SupervisorBehavior")
	}
	spec, err := behavior.Init(args...)
	if err != nil {
		return ProcessState{}, err
	}
	lib.Log("Supervisor spec %#v\n", spec)
	p.SetTrapExit(true)
	return ProcessState{
		Process: p,
		State:   &spec,
	}, nil
}
func (sv *Supervisor) ProcessLoop(ps ProcessState, started chan<- bool) string {
	spec := ps.State.(*SupervisorSpec)
	if spec.Strategy.Type != SupervisorStrategySimpleOneForOne {
		startChildren(ps, spec)
	}
	waitTerminatingProcesses := []etf.Pid{}
	chs := ps.ProcessChannels()
	started <- true
	for {
		select {
		case ex := <-chs.GracefulExit:
			if ex.From == ps.Self() {
				for i := range spec.Children {
					p := spec.Children[i].process
					if p != nil && p.IsAlive() {
						p.Exit(ex.Reason)
					}
				}
				return ex.Reason
			}
			waitTerminatingProcesses = handleMessageExit(ps, ex, spec, waitTerminatingProcesses)
		case <-ps.Context().Done():
			return "kill"
		case direct := <-chs.Direct:
			value, err := handleDirect(ps, spec, direct.Message)
			if err != nil {
				direct.Message = nil
				direct.Err = err
				direct.Reply <- direct
				continue
			}
			direct.Message = value
			direct.Err = nil
			direct.Reply <- direct
		case <-chs.Mailbox:
		}
	}
}