func (w *Workflow) DelChild(n Node) {
	w.bn.DelChild(n)
}
DelChild deletes a child from the workflow
package astiencoder
import (
	"context"
	"fmt"
	"github.com/asticode/go-astikit"
)
type Workflow struct {
	bn   *BaseNode
	c    *astikit.Closer
	ctx  context.Context
	eh   *EventHandler
	name string
	t    *astikit.Task
	tf   CreateTaskFunc
}
func NewWorkflow(ctx context.Context, name string, eh *EventHandler, tf CreateTaskFunc, c *astikit.Closer) (w *Workflow) {
	w = &Workflow{
		c:    c,
		ctx:  ctx,
		eh:   eh,
		name: name,
		tf:   tf,
	}
	w.bn = NewBaseNode(NodeOptions{Metadata: NodeMetadata{
		Description: "root",
		Label:       "root",
		Name:        "root",
	}}, eh, nil, w, EventTypeToWorkflowEventName)
	return
}
func (w *Workflow) Name() string {
	return w.name
}
func (w *Workflow) nodes() (ns []Node) {
	for _, n := range w.indexedNodes() {
		ns = append(ns, n)
	}
	return
}
func (w *Workflow) indexedNodes() (ns map[string]Node) {
	ns = make(map[string]Node)
	w.indexedNodesFunc(ns, w.bn.Children())
	return
}
func (w *Workflow) indexedNodesFunc(ns map[string]Node, children []Node) {
	for _, n := range children {
		ns[n.Metadata().Name] = n
		w.indexedNodesFunc(ns, n.Children())
	}
}
func (w *Workflow) StartNodes(ns ...Node) {
	for _, n := range ns {
		n.Start(w.bn.Context(), w.t.NewSubTask)
	}
}
func (w *Workflow) StartNodesInSubTask(ns ...Node) (t *astikit.Task) {
	t = w.t.NewSubTask()
	for _, n := range ns {
		n.Start(w.bn.Context(), t.NewSubTask)
	}
	return
}
type WorkflowStartOptions struct {
	Groups []WorkflowStartGroup
}
type WorkflowStartGroup struct {
	Callback func(t *astikit.Task)
	Nodes    []Node
}
func (w *Workflow) Start() {
	w.start(w.nodes(), WorkflowStartOptions{})
}
func (w *Workflow) StartWithOptions(o WorkflowStartOptions) {
	w.start(w.nodes(), o)
}
type workflowStartGroup struct {
	fn func(t *astikit.Task)
	ns []Node
	t  *astikit.Task
}
func (w *Workflow) start(ns []Node, o WorkflowStartOptions) {
	w.bn.Start(w.ctx, w.tf, func(t *astikit.Task) {
		w.t = t
		var gs []*workflowStartGroup
		ngs := make(map[Node]*workflowStartGroup)
		for _, og := range o.Groups {
			g := &workflowStartGroup{fn: og.Callback}
			for _, n := range og.Nodes {
				ngs[n] = g
			}
			gs = append(gs, g)
		}
		for _, n := range ns {
			if g, ok := ngs[n]; ok {
				g.ns = append(g.ns, n)
			} else {
				w.StartNodes(n)
			}
		}
		for _, g := range gs {
			g.t = w.StartNodesInSubTask(g.ns...)
		}
		for _, g := range gs {
			if g.fn != nil {
				g.fn(g.t)
			}
		}
		t.Wait()
		if err := w.c.Close(); err != nil {
			w.eh.Emit(EventError(w, fmt.Errorf("astiencoder: closing workflow %s failed: %w", w.name, err)))
		}
	})
}
func (w *Workflow) Stop() {
	w.bn.Stop()
}
func (w *Workflow) Pause() {
	w.bn.pauseFunc(func() {
		for _, n := range w.nodes() {
			n.Pause()
		}
	})
}
func (w *Workflow) Continue() {
	w.bn.continueFunc(func() {
		for _, n := range w.nodes() {
			n.Continue()
		}
	})
}
func (w *Workflow) AddChild(n Node) {
	w.bn.AddChild(n)
}