2 Commits

Author SHA1 Message Date
44218ec4ac with state in funcs 2022-09-10 20:05:10 +02:00
a2c53271e4 with public func 2022-09-10 19:55:19 +02:00

View File

@@ -3,9 +3,9 @@ package curre
import "context" import "context"
type FunctionalComponent struct { type FunctionalComponent struct {
init func(ctx context.Context) error InitFunc func(fc *FunctionalComponent, ctx context.Context) error
start func(ctx context.Context) error StartFunc func(fc *FunctionalComponent, ctx context.Context) error
stop func(ctx context.Context) error StopFunc func(fc *FunctionalComponent, ctx context.Context) error
} }
func NewFunctionalComponent( func NewFunctionalComponent(
@@ -15,20 +15,20 @@ func NewFunctionalComponent(
} }
func (fc *FunctionalComponent) Init(ctx context.Context) error { func (fc *FunctionalComponent) Init(ctx context.Context) error {
if fc.init != nil { if fc.InitFunc != nil {
return fc.init(ctx) return fc.InitFunc(fc, ctx)
} }
return nil return nil
} }
func (fc *FunctionalComponent) Start(ctx context.Context) error { func (fc *FunctionalComponent) Start(ctx context.Context) error {
if fc.start != nil { if fc.StartFunc != nil {
return fc.start(ctx) return fc.StartFunc(fc, ctx)
} }
return nil return nil
} }
func (fc *FunctionalComponent) Stop(ctx context.Context) error { func (fc *FunctionalComponent) Stop(ctx context.Context) error {
if fc.stop != nil { if fc.StopFunc != nil {
return fc.stop(ctx) return fc.StopFunc(fc, ctx)
} }
return nil return nil
} }