@@ -842,7 +842,8 @@ func GroupWhen1(
842842 return chans , nil
843843}
844844
845- // TODO func WhenAny1(mach am.Api, states am.S, ctx context.Context) []<-chan struct{}
845+ // TODO func WhenAny1(mach am.Api, states am.S, ctx context.Context)
846+ // []<-chan struct{}
846847
847848// RemoveMulti creates a final handler which removes a multi state from a
848849// machine. Useful to avoid FooState-Remove1-Foo repetition.
@@ -928,7 +929,8 @@ func Pool(limit int) *errgroup.Group {
928929 return g
929930}
930931
931- // Cond is a set of state conditions, which when all met make the condition true.
932+ // Cond is a set of state conditions, which when all met make the condition
933+ // true.
932934type Cond struct {
933935 // TODO IsMatch, AnyMatch, ... for regexps
934936
@@ -951,10 +953,12 @@ type Cond struct {
951953}
952954
953955func (c Cond ) String () string {
954- return fmt .Sprintf ("is: %s, any: %s, not: %s, clock: %v" , c .Is , c .Any1 , c .Not , c .Clock )
956+ return fmt .Sprintf ("is: %s, any: %s, not: %s, clock: %v" ,
957+ c .Is , c .Any1 , c .Not , c .Clock )
955958}
956959
957- // Check compares the specified conditions against the passed machine. When mach is nil, Check returns false.
960+ // Check compares the specified conditions against the passed machine. When mach
961+ // is nil, Check returns false.
958962func (c Cond ) Check (mach am.Api ) bool {
959963 if mach == nil {
960964 return false
@@ -984,23 +988,19 @@ func (c Cond) IsEmpty() bool {
984988// TODO thread safety via atomics
985989type StateLoop struct {
986990 loopState string
991+ ctxStates am.S
987992 mach am.Api
988993 ended bool
989994 interval time.Duration
990995 threshold int
991-
992- // state context of loopState
993- ctx context.Context
994- ctxStates am.S
996+ check func () bool
995997
996998 lastSTime uint64
997999 lastHTime time.Time
998-
999- // Start State Time of ctxStates
1000+ // mach time of [ctxStates] when started
10001001 startSTime uint64
10011002 // Start Human Time
10021003 startHTime time.Time
1003- check func () bool
10041004}
10051005
10061006func (l * StateLoop ) String () string {
@@ -1025,19 +1025,19 @@ func (l *StateLoop) Sum() uint64 {
10251025
10261026// Ok returns true if the loop should continue.
10271027func (l * StateLoop ) Ok (ctx context.Context ) bool {
1028-
10291028 if l .ended {
10301029 return false
1031-
10321030 } else if ctx != nil && ctx .Err () != nil {
1033- err := fmt .Errorf ("loop: arg ctx expired for %s/%s" , l .mach .Id (), l .loopState )
1031+ err := fmt .Errorf ("loop: arg ctx expired for %s/%s" , l .mach .Id (),
1032+ l .loopState )
10341033 l .mach .AddErr (err , nil )
10351034 l .ended = true
10361035
10371036 return false
10381037
10391038 } else if l .mach .Not1 (l .loopState ) {
1040- err := fmt .Errorf ("loop: state ctx expired for %s/%s" , l .mach .Id (), l .loopState )
1039+ err := fmt .Errorf ("loop: state ctx expired for %s/%s" , l .mach .Id (),
1040+ l .loopState )
10411041 l .mach .AddErr (err , nil )
10421042 l .ended = true
10431043
@@ -1061,7 +1061,8 @@ func (l *StateLoop) Ok(ctx context.Context) bool {
10611061
10621062 // check the current interval window
10631063 } else if int (sum ) > l .threshold {
1064- err := fmt .Errorf ("loop: threshold exceeded for %s/%s" , l .mach .Id (), l .loopState )
1064+ err := fmt .Errorf ("loop: threshold exceeded for %s/%s" , l .mach .Id (),
1065+ l .loopState )
10651066 l .mach .AddErr (err , nil )
10661067 l .ended = true
10671068
@@ -1086,7 +1087,6 @@ func (l *StateLoop) Ended() bool {
10861087func NewStateLoop (
10871088 mach * am.Machine , loopState string , optCheck func () bool ,
10881089) * StateLoop {
1089-
10901090 schema := mach .Schema ()
10911091 mach .MustParseStates (S {loopState })
10921092
@@ -1150,7 +1150,6 @@ func (l SlogToMachLog) Write(p []byte) (n int, err error) {
11501150// TagValue returns the value part from a text tag "key:value". For tag without
11511151// value, it returns the tag name.
11521152func TagValue (tags []string , key string ) string {
1153-
11541153 for _ , t := range tags {
11551154 // no value
11561155 if t == key {
@@ -1174,7 +1173,8 @@ func TagValue(tags []string, key string) string {
11741173// overlaps eg "FooFooName" will be "Foo".
11751174func PrefixStates (
11761175 schema am.Schema , prefix string , removeDups bool , optWhitelist ,
1177- optBlacklist S ) am.Schema {
1176+ optBlacklist S ,
1177+ ) am.Schema {
11781178 schema = am .CloneSchema (schema )
11791179
11801180 for name , s := range schema {
0 commit comments