2 Commits

Author SHA1 Message Date
3b3c0e6118 as function instead 2022-09-10 19:53:19 +02:00
78c0c309d7 with fc 2022-09-10 13:08:16 +02:00
5 changed files with 39 additions and 5 deletions

34
builder.go Normal file
View File

@@ -0,0 +1,34 @@
package curre
import "context"
type FunctionalComponent struct {
init func(ctx context.Context) error
start func(ctx context.Context) error
stop func(ctx context.Context) error
}
func NewFunctionalComponent(
fc *FunctionalComponent,
) Component {
return fc
}
func (fc *FunctionalComponent) Init(ctx context.Context) error {
if fc.init != nil {
return fc.init(ctx)
}
return nil
}
func (fc *FunctionalComponent) Start(ctx context.Context) error {
if fc.start != nil {
return fc.start(ctx)
}
return nil
}
func (fc *FunctionalComponent) Stop(ctx context.Context) error {
if fc.stop != nil {
return fc.stop(ctx)
}
return nil
}

View File

@@ -2,6 +2,6 @@ package curre
import "context"
type Closer interface {
Close(ctx context.Context) error
type Stopper interface {
Stop(ctx context.Context) error
}

View File

@@ -3,5 +3,5 @@ package curre
type Component interface {
Initer
Starter
Closer
Stopper
}

View File

@@ -28,6 +28,6 @@ func (hs *httpServer) Start(ctx context.Context) error {
return nil
}
func (hs *httpServer) Close(ctx context.Context) error {
func (hs *httpServer) Stop(ctx context.Context) error {
return nil
}

View File

@@ -139,7 +139,7 @@ func (m *Manager) shutdown(ctx context.Context) error {
go func(ctx context.Context) {
for _, c := range closers {
c.Close(ctx)
c.Stop(ctx)
}
shutdownChan <- struct{}{}