forked from mtusi2026/mtusi2026lab7
Prepare verified laboratory 7 implementation and evidence
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
// Package lifecycle connects an explicitly supplied health monitor to composition cancellation.
|
||||
package lifecycle
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type Ports struct {
|
||||
Watch func(context.Context) error
|
||||
Stop func()
|
||||
Report func()
|
||||
}
|
||||
type Runner struct{ ports Ports }
|
||||
|
||||
var ErrConfiguration = errors.New("invalid lifecycle configuration")
|
||||
|
||||
func New(p Ports) (*Runner, error) {
|
||||
if p.Watch == nil || p.Stop == nil || p.Report == nil {
|
||||
return nil, ErrConfiguration
|
||||
}
|
||||
return &Runner{p}, nil
|
||||
}
|
||||
func (r *Runner) Run(ctx context.Context) {
|
||||
if e := r.ports.Watch(ctx); e != nil && ctx.Err() == nil {
|
||||
r.ports.Report()
|
||||
r.ports.Stop()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user