Ejemplo n.º 1
0
func (d *Dwimmer) Run(setting *term.SettingT) term.T {
	goMeta := func() {
		StartShell(d, Interrupted.T(represent.SettingT(setting)))
	}
	for {
		//d.watchdog(setting)
		char, sent := d.CheckCh()
		if sent {
			if char == 'q' {
				panic("interrupted")
			} else if char == 's' {
				goMeta()
			} else {
				d.Clear()
				d.Debug("(Type [s] to interrupt execution and drop into a shell)")
				d.Debug("(Type [q] to interrupt execution and quit)")
			}
		}
		transition, ok := d.Get(setting.Setting)
		if !ok {
			transition = ElicitAction(d, setting.Copy(), setting.Setting)
		}
		result := transition.Step(d, setting)
		if result != nil {
			return result
		}
	}
}
Ejemplo n.º 2
0
func (d *Dwimmer) watchdog(setting *term.SettingT) {
	if rand.Int()%(watchFrequency<<(3*watcherDepth)) == 0 {
		watcherDepth++
		defer func() { watcherDepth-- }()
		parent := setting.Copy().AppendAction(term.MetaC())
		oldWatcher := d.lastWatcher
		newWatcher := term.InitT()
		var Q term.T
		if d.lastWatcher == nil {
			Q = IsAllWell.T(term.MakeChannel(parent))
		} else {
			Q = IsAllWellPred.T(term.MakeChannel(parent), term.MakeChannel(oldWatcher))
		}
		d.lastWatcher = newWatcher
		dynamics.SubRun(d, Q, parent, newWatcher)
	}
}