with fc
This commit is contained in:
parent
33ac911f9c
commit
78c0c309d7
23
builder.go
Normal file
23
builder.go
Normal file
@ -0,0 +1,23 @@
|
||||
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(
|
||||
init func(ctx context.Context) error,
|
||||
start func(ctx context.Context) error,
|
||||
stop func(ctx context.Context) error,
|
||||
) Component {
|
||||
return &FunctionalComponent{
|
||||
init, start, stop,
|
||||
}
|
||||
}
|
||||
|
||||
func (fc *FunctionalComponent) Init(ctx context.Context) error { return fc.init(ctx) }
|
||||
func (fc *FunctionalComponent) Start(ctx context.Context) error { return fc.start(ctx) }
|
||||
func (fc *FunctionalComponent) Stop(ctx context.Context) error { return fc.stop(ctx) }
|
@ -2,6 +2,6 @@ package curre
|
||||
|
||||
import "context"
|
||||
|
||||
type Closer interface {
|
||||
Close(ctx context.Context) error
|
||||
type Stopper interface {
|
||||
Stop(ctx context.Context) error
|
||||
}
|
||||
|
@ -3,5 +3,5 @@ package curre
|
||||
type Component interface {
|
||||
Initer
|
||||
Starter
|
||||
Closer
|
||||
Stopper
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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{}{}
|
||||
|
Loading…
Reference in New Issue
Block a user