with state in funcs

This commit is contained in:
Kasper Juul Hermansen 2022-09-10 20:05:10 +02:00
parent a2c53271e4
commit 44218ec4ac
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912

View File

@ -3,9 +3,9 @@ package curre
import "context" import "context"
type FunctionalComponent struct { type FunctionalComponent struct {
InitFunc func(ctx context.Context) error InitFunc func(fc *FunctionalComponent, ctx context.Context) error
StartFunc func(ctx context.Context) error StartFunc func(fc *FunctionalComponent, ctx context.Context) error
StopFunc func(ctx context.Context) error StopFunc func(fc *FunctionalComponent, ctx context.Context) error
} }
func NewFunctionalComponent( func NewFunctionalComponent(
@ -16,19 +16,19 @@ func NewFunctionalComponent(
func (fc *FunctionalComponent) Init(ctx context.Context) error { func (fc *FunctionalComponent) Init(ctx context.Context) error {
if fc.InitFunc != nil { if fc.InitFunc != nil {
return fc.InitFunc(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.StartFunc != nil { if fc.StartFunc != nil {
return fc.StartFunc(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.StopFunc != nil { if fc.StopFunc != nil {
return fc.StopFunc(ctx) return fc.StopFunc(fc, ctx)
} }
return nil return nil
} }