diff --git a/examples/helloworld.yaml b/examples/helloworld.yaml index 42e2c8cc..34b40e5c 100644 --- a/examples/helloworld.yaml +++ b/examples/helloworld.yaml @@ -7,12 +7,9 @@ - kind: print filename: /dev/stdout ports: - init: + begin: - name: hello_world port: in - env: - PORT: - - data: '{{ .PORT }}' - kind: step name: good_bye diff --git a/pkg/node/port.go b/pkg/node/port.go index 48324d88..470996a3 100644 --- a/pkg/node/port.go +++ b/pkg/node/port.go @@ -9,14 +9,16 @@ import ( // Commonly used port names. const ( PortInit = "init" + PortBegin = "begin" PortTerm = "term" + PortFinal = "final" PortIO = "io" PortIn = "in" PortOut = "out" PortError = "error" ) -var portExp = regexp.MustCompile(`(\w+)\[(\d+)\]`) +var subscript = regexp.MustCompile(`(\w+)\[(\d+)\]`) // PortWithIndex formats the port name as "name[index]". func PortWithIndex(name string, index int) string { @@ -24,16 +26,16 @@ func PortWithIndex(name string, index int) string { } // NameOfPort extracts the base name from a port name formatted as "name[index]". -func NameOfPort(name string) string { - if groups := portExp.FindStringSubmatch(name); groups != nil { +func NameOfPort(key string) string { + if groups := subscript.FindStringSubmatch(key); groups != nil { return groups[1] } - return name + return key } // IndexOfPort extracts the index from a port name formatted as "name[index]". -func IndexOfPort(name string) (int, bool) { - if groups := portExp.FindStringSubmatch(name); len(groups) == 3 { +func IndexOfPort(key string) (int, bool) { + if groups := subscript.FindStringSubmatch(key); len(groups) == 3 { if index, err := strconv.Atoi(groups[2]); err == nil { return index, true } diff --git a/pkg/symbol/loader.go b/pkg/symbol/loader.go index 95464a22..d4ab43f9 100644 --- a/pkg/symbol/loader.go +++ b/pkg/symbol/loader.go @@ -3,9 +3,9 @@ package symbol import ( "context" "errors" - "github.com/iancoleman/strcase" "reflect" + "github.com/iancoleman/strcase" "github.com/siyul-park/uniflow/pkg/resource" "github.com/siyul-park/uniflow/pkg/scheme" "github.com/siyul-park/uniflow/pkg/spec" diff --git a/pkg/symbol/table.go b/pkg/symbol/table.go index 2c2622fe..8aa34a8a 100644 --- a/pkg/symbol/table.go +++ b/pkg/symbol/table.go @@ -155,7 +155,7 @@ func (t *Table) Keys() []uuid.UUID { t.mu.RLock() defer t.mu.RUnlock() - var ids []uuid.UUID + ids := make([]uuid.UUID, 0, len(t.symbols)) for id := range t.symbols { ids = append(ids, id) } @@ -272,10 +272,13 @@ func (t *Table) load(sb *Symbol) error { linked := t.linked(sb) for _, sb := range linked { if t.active(sb) { + if err := t.call(sb, node.PortInit); err != nil { + return err + } if err := t.loadHooks.Load(sb); err != nil { return err } - if err := t.call(sb, node.PortInit); err != nil { + if err := t.call(sb, node.PortBegin); err != nil { return err } } @@ -294,6 +297,9 @@ func (t *Table) unload(sb *Symbol) error { if err := t.unloadHooks.Unload(sb); err != nil { return err } + if err := t.call(sb, node.PortFinal); err != nil { + return err + } } } return nil