Files
monibuca/pkg/unit.go
T
2024-03-29 17:15:17 +08:00

29 lines
467 B
Go

package pkg
import (
"context"
"log/slog"
"time"
)
type Unit struct {
StartTime time.Time
*slog.Logger `json:"-" yaml:"-"`
context.Context `json:"-" yaml:"-"`
context.CancelCauseFunc `json:"-" yaml:"-"`
}
func (unit *Unit) IsStopped() bool {
select {
case <-unit.Done():
return true
default:
}
return false
}
func (unit *Unit) Stop(err error) {
unit.Info("stop", "reason", err.Error())
unit.CancelCauseFunc(err)
}