Skip to content

Commit 5493dbe

Browse files
committed
chore: fix lint and format
1 parent 1b5aa7a commit 5493dbe

File tree

24 files changed

+92
-100
lines changed

24 files changed

+92
-100
lines changed

FAQ.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ aRPC auto syncs only clock values, which technically is `[n]uint64` (`n` = numbe
5252

5353
## Does asyncmachine return data?
5454

55-
No, just yes/no/later (`Executed`, `Canceled`, `Queued`). Use channels in mutation args for returning local data and the `SendPayload` state for aRPC.
55+
No, just yes/no/later (`Executed`, `Canceled`, `Queued`). Use channels in mutation args for returning local data and
56+
the `SendPayload` state for aRPC.
5657

5758
## Does asyncmachine return errors?
5859

@@ -75,7 +76,8 @@ with `amhelp.Pool` (`errgroup`) per a state, machine, or both. It's a form of st
7576

7677
## What should be a "state"?
7778

78-
Only interesting things - if we don't care about something to be a separate entity, there's no need to orchestrate it as a separate state.
79+
Only interesting things - if we don't care about something to be a separate entity, there's no need to orchestrate it
80+
as a separate state.
7981

8082
## What's the origin of asyncmachine?
8183

README.md

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,13 @@ The top layers depend on the bottom ones.
8484
<td>.</td>
8585
<td>.</td>
8686
<td>.</td>
87-
<td>.</td>
88-
<td>.</td>
8987
<td colspan="1" align=center><a href="pkg/pubsub/README.md">PubSub</a></td>
9088
<td>.</td>
9189
<td>.</td>
9290
<td>.</td>
9391
<td>.</td>
9492
<td>.</td>
9593
<td>.</td>
96-
<td>.</td>
97-
<td>.</td>
98-
<td>.</td>
9994
</tr>
10095

10196
<tr>
@@ -104,79 +99,54 @@ The top layers depend on the bottom ones.
10499
<td>.</td>
105100
<td>.</td>
106101
<td>.</td>
107-
<td>.</td>
108-
<td>.</td>
109102
<td colspan="3" align=center><a href="pkg/node/README.md">Workers</a></td>
110103
<td>.</td>
111104
<td>.</td>
112105
<td>.</td>
113106
<td>.</td>
114107
<td>.</td>
115-
<td>.</td>
116-
<td>.</td>
117-
<td>.</td>
118108
</tr>
119109

120110
<tr>
121111
<td>.</td>
122112
<td>.</td>
123113
<td>.</td>
124114
<td>.</td>
125-
<td>.</td>
126-
<td>.</td>
127115
<td colspan="5" align=center><a href="pkg/rpc/README.md">RPC</a></td>
128116
<td>.</td>
129117
<td>.</td>
130118
<td>.</td>
131119
<td>.</td>
132-
<td>.</td>
133-
<td>.</td>
134120
</tr>
135121

136122
<tr>
137-
<td>.</td>
138-
<td>.</td>
139123
<td>.</td>
140124
<td>.</td>
141125
<td>.</td>
142126
<td colspan="7" align=center><a href="pkg/machine/README.md#aop-handlers">Handlers</a></td>
143127
<td>.</td>
144128
<td>.</td>
145129
<td>.</td>
146-
<td>.</td>
147-
<td>.</td>
148130
</tr>
149131

150132
<tr>
151-
<td>.</td>
152-
<td>.</td>
153133
<td>.</td>
154134
<td>.</td>
155135
<td colspan="9" align=center>🐇 <a href="pkg/machine/README.md">Machine API</a></td>
156136
<td>.</td>
157137
<td>.</td>
158-
<td>.</td>
159-
<td>.</td>
160138
</tr>
161139

162140
<tr>
163-
<td>.</td>
164-
<td>.</td>
165141
<td>.</td>
166142
<td colspan="11" align=center><a href="pkg/machine/README.md#relations">Relations</a></td>
167143
<td>.</td>
168-
<td>.</td>
169-
<td>.</td>
170144
</tr>
171145

172146
<tr>
173-
<td>.</td>
174-
<td>.</td>
175147
<td colspan="13" align=center><a href="pkg/machine/README.md#multi-state"><b><u>
176148
States
177149
</u></b></a></td>
178-
<td>.</td>
179-
<td>.</td>
180150
</tr>
181151
</table>
182152

@@ -295,7 +265,7 @@ All examples and benchmarks can be found in [`/examples`](/examples/README.md).
295265
- 🦾 **[`/pkg/machine`](pkg/machine/README.md)** is the main package
296266
- [`/pkg/node`](pkg/node) shows a high-level usage
297267
- examples in [`/examples`](/examples/README.md) are good for a general grasp
298-
- with [`/examples/mach_template`](/examples/mach_template) being ready for copy-paste
268+
- with [`/examples/mach_template`](/examples/mach_template) being ready for copy-paste
299269
- [`/docs/manual.md`](/docs/manual.md)
300270
and [`/docs/diagrams.md`](/docs/diagrams.md) go deeper into implementation details
301271
- [`/tools/cmd/am-gen`](/tools/cmd/am-gen) will bootstrap
@@ -349,7 +319,7 @@ Other packages:
349319
- [Changing State](/docs/manual.md#changing-state)
350320
- [Advanced Topics](/docs/manual.md#advanced-topics)
351321
- [Cheatsheet](/docs/manual.md#cheatsheet)
352-
322+
353323
## Goals
354324

355325
- scale up, not down

examples/tree_state_source/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ type FlightsStatesDef struct {
3838

3939
// ...
4040

41-
// inherit from BasicStatesDef
42-
*ssam.BasicStatesDef
41+
// inherit from BasicStatesDef
42+
*ssam.BasicStatesDef
4343
// inherit from rpc/WorkerStatesDef
4444
*ssrpc.WorkerStatesDef
4545
}

pkg/helpers/help.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
932934
type Cond struct {
933935
// TODO IsMatch, AnyMatch, ... for regexps
934936

@@ -951,10 +953,12 @@ type Cond struct {
951953
}
952954

953955
func (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.
958962
func (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
985989
type 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

10061006
func (l *StateLoop) String() string {
@@ -1025,19 +1025,19 @@ func (l *StateLoop) Sum() uint64 {
10251025

10261026
// Ok returns true if the loop should continue.
10271027
func (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 {
10861087
func 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.
11521152
func 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".
11751174
func 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 {

pkg/machine/machine.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,7 +1623,6 @@ func (m *Machine) VerifyStates(states S) error {
16231623
}
16241624

16251625
func (m *Machine) verifyStates(states S) error {
1626-
16271626
var errs []error
16281627
var checked []string
16291628
for _, s := range states {
@@ -2155,8 +2154,8 @@ func (m *Machine) Log(msg string, args ...any) {
21552154
m.log(LogChanges, prefix+"] "+msg, args...)
21562155
}
21572156

2158-
// InternalLog adds an internal log entry from the outside. It should be used only
2159-
// by packages extending pkg/machine. Use Log instead.
2157+
// InternalLog adds an internal log entry from the outside. It should be used
2158+
// only by packages extending pkg/machine. Use Log instead.
21602159
func (m *Machine) InternalLog(lvl LogLevel, msg string, args ...any) {
21612160
if m.disposed.Load() {
21622161
return

pkg/machine/machine_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -938,8 +938,8 @@ func (h *TestHandlerStateInfoHandlers) DEnter(e *Event) {
938938
"provide the target states of the transition")
939939
assert.True(t, e.Mutation().IsCalled(idxD),
940940
"provide the called states of the transition")
941-
txStrExp := "tx#" + e.TransitionId + "\n[set] D\n- requested **D**\n- activate **D**\n" +
942-
"- deactivate **A**\n- handler **A**Exit"
941+
txStrExp := "tx#" + e.TransitionId + "\n[set] D\n- requested **D**\n" +
942+
"- activate **D**\n- deactivate **A**\n- handler **A**Exit"
943943
txStr := e.Transition().String()
944944
assert.Equal(t, txStrExp, txStr,
945945
"provide a string version of the transition")

pkg/machine/transition.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ type Transition struct {
1919
// TimeBefore is the machine time from before the transition.
2020
TimeBefore Time
2121
// TimeAfter is the machine time from after the transition. If the transition
22-
// has been canceled, this will be the same as TimeBefore. This field is nil until the negotiation phase finishes.
22+
// has been canceled, this will be the same as TimeBefore. This field is nil
23+
// until the negotiation phase finishes.
2324
TimeAfter Time
2425
// TargetIndexes is a list of indexes of the target states.
2526
TargetIndexes []int
@@ -265,9 +266,10 @@ func (t *Transition) String() string {
265266
}
266267

267268
source := ""
268-
if t.Mutation.Source != nil {
269-
source = fmt.Sprintf("\nsource: [%s](%s/%s/t%d)", t.Mutation.Source.TxId,
270-
t.Mutation.Source.MachId, t.Mutation.Source.TxId, t.Mutation.Source.MachTime)
269+
mutSrc := t.Mutation.Source
270+
if mutSrc != nil {
271+
source = fmt.Sprintf("\nsource: [%s](%s/%s/t%d)", mutSrc.TxId,
272+
mutSrc.MachId, mutSrc.TxId, mutSrc.MachTime)
271273
}
272274

273275
return fmt.Sprintf("tx#%s\n%s%s%s", t.ID, t.Mutation.StringFromIndex(index),
@@ -368,7 +370,6 @@ func (t *Transition) emitExitEvents() Result {
368370
func (t *Transition) emitHandler(
369371
from, to string, isFinal, isEnter bool, event string, args A,
370372
) Result {
371-
372373
step := newStep(from, to, StepHandler, 0)
373374
step.IsFinal = isFinal
374375
step.IsEnter = isEnter
@@ -516,7 +517,6 @@ func (t *Transition) emitEvents() Result {
516517
result = t.emitFinalEvents()
517518
hasStateChanged = !m.IsTime(t.TimeBefore, nil)
518519
} else {
519-
520520
// gather new clock values, overwrite fake TimeAfter
521521
t.TimeAfter = t.TimeBefore
522522
}

pkg/machine/types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,6 @@ func (s *Step) StringFromIndex(idx S) string {
517517
func newStep(from string, to string, stepType StepType,
518518
relType Relation,
519519
) *Step {
520-
521520
ret := &Step{
522521
// TODO refac with the new dbg protocol, use indexes only
523522
FromState: from,

pkg/pubsub/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ State schema from [/pkg/pubsub/states/](/pkg/pubsub/states/ss_topic.go).
6161
import (
6262
ma "github.com/multiformats/go-multiaddr"
6363
ampubsub "github.com/pancsta/asyncmachine-go/pkg/pubsub"
64-
ssps "github.com/pancsta/asyncmachine-go/pkg/pubsub/states"
64+
ssps "github.com/pancsta/asyncmachine-go/pkg/pubsub/states"
6565
)
6666

6767
var ss = states.TopicStates

pkg/rpc/rpc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"time"
1919

2020
"github.com/cenkalti/rpc2"
21+
2122
"github.com/pancsta/asyncmachine-go/pkg/rpc/rpcnames"
2223

2324
"github.com/pancsta/asyncmachine-go/internal/utils"

0 commit comments

Comments
 (0)