diff --git a/examples/benchmark_grpc/client_local_test.go b/examples/benchmark_grpc/client_local_test.go index 18ea87d..23003bf 100644 --- a/examples/benchmark_grpc/client_local_test.go +++ b/examples/benchmark_grpc/client_local_test.go @@ -15,7 +15,6 @@ func BenchmarkClientLocal(b *testing.B) { // 2. getter: get a value from the worker // 3. processing: call an operation based on the value worker.Subscribe(func() { - // loop i++ if i > limit { diff --git a/examples/benchmark_grpc/server_arpc.go b/examples/benchmark_grpc/server_arpc.go index 83e1124..60121ff 100644 --- a/examples/benchmark_grpc/server_arpc.go +++ b/examples/benchmark_grpc/server_arpc.go @@ -22,7 +22,6 @@ type WorkerArpcServer struct { func NewWorkerArpcServer( ctx context.Context, addr string, worker *Worker, ) (*WorkerArpcServer, error) { - // validate if worker == nil { return nil, errors.New("worker is nil") diff --git a/pkg/machine/machine.go b/pkg/machine/machine.go index 040c7ed..db76bb7 100644 --- a/pkg/machine/machine.go +++ b/pkg/machine/machine.go @@ -1983,7 +1983,6 @@ func (m *Machine) processHandlers(e *Event) (Result, bool) { // returns from State and End handlers are ignored default: if !ret { - return Canceled, handlerCalled } } diff --git a/pkg/machine/misc.go b/pkg/machine/misc.go index 3a55454..18c53f3 100644 --- a/pkg/machine/misc.go +++ b/pkg/machine/misc.go @@ -489,8 +489,6 @@ type ( IndexWhenArgs map[string][]*WhenArgsBinding // IndexStateCtx is a map of (single) state names to a context cancel function IndexStateCtx map[string][]context.CancelFunc - // map of (single) state names to an event channel - indexEventCh map[string][]chan *Event ) type WhenBinding struct { diff --git a/pkg/machine/misc_test.go b/pkg/machine/misc_test.go index 0411662..16c3b7a 100644 --- a/pkg/machine/misc_test.go +++ b/pkg/machine/misc_test.go @@ -2,7 +2,6 @@ package machine import ( "context" - "os" "testing" "time" @@ -129,11 +128,3 @@ func TestIsActiveTick(t *testing.T) { assert.False(t, IsActiveTick(6548734)) assert.True(t, IsActiveTick(6548735)) } - -func fileExists(filePath string) bool { - _, err := os.Stat(filePath) - if os.IsNotExist(err) { - return false - } - return err == nil -} diff --git a/pkg/machine/popup_test.go b/pkg/machine/popup_test.go index 7cdf1df..71f87bb 100644 --- a/pkg/machine/popup_test.go +++ b/pkg/machine/popup_test.go @@ -5,8 +5,9 @@ import ( "testing" "time" - am "github.com/pancsta/asyncmachine-go/pkg/machine" "github.com/stretchr/testify/assert" + + am "github.com/pancsta/asyncmachine-go/pkg/machine" ) func NewPopupMachine(ctx context.Context) *am.Machine { diff --git a/pkg/machine/transition.go b/pkg/machine/transition.go index 7bd8632..8ae7424 100644 --- a/pkg/machine/transition.go +++ b/pkg/machine/transition.go @@ -394,7 +394,6 @@ func (t *Transition) emitEvents() Result { // AUTO STATES if result == Canceled { - t.Accepted = false } else if hasStateChanged && !t.IsAuto() { diff --git a/pkg/machine/utils_test.go b/pkg/machine/utils_test.go index f261928..913739b 100644 --- a/pkg/machine/utils_test.go +++ b/pkg/machine/utils_test.go @@ -29,7 +29,6 @@ func (h *History) AC(e *Event) { func (h *History) AExit(e *Event) { h.event("AExit") - } func (h *History) AA(e *Event) { @@ -64,7 +63,6 @@ func (h *History) AnyB(e *Event) { func (h *History) BExit(e *Event) { h.event("BExit") - } func (h *History) BD(e *Event) { diff --git a/pkg/rpc/client.go b/pkg/rpc/client.go index 96bc80f..92a6b5e 100644 --- a/pkg/rpc/client.go +++ b/pkg/rpc/client.go @@ -36,8 +36,10 @@ type Client struct { } // interfaces -var _ clientRpcMethods = &Client{} -var _ clientServerMethods = &Client{} +var ( + _ clientRpcMethods = &Client{} + _ clientServerMethods = &Client{} +) func NewClient( ctx context.Context, workerAddr string, id string, stateStruct am.Struct, @@ -182,7 +184,7 @@ func (c *Client) HandshakingState(e *am.Event) { go func() { // call rpc - var resp = &RespHandshake{} + resp := &RespHandshake{} if !c.call(ctx, rpcnames.Handshake.Encode(), Empty{}, resp) { return } diff --git a/pkg/rpc/rpc_machine_test.go b/pkg/rpc/rpc_machine_test.go index aa04e6a..552dcf7 100644 --- a/pkg/rpc/rpc_machine_test.go +++ b/pkg/rpc/rpc_machine_test.go @@ -18,8 +18,10 @@ import ( type S = am.S // type A = am.A -type State = am.State -type Struct = am.Struct +type ( + State = am.State + Struct = am.Struct +) func init() { if os.Getenv("AM_TEST_DEBUG") != "" { diff --git a/pkg/rpc/rpc_test.go b/pkg/rpc/rpc_test.go index c3310d8..22b76ff 100644 --- a/pkg/rpc/rpc_test.go +++ b/pkg/rpc/rpc_test.go @@ -389,7 +389,6 @@ func NewTest( t *testing.T, ctx context.Context, worker *am.Machine, disposeMeter <-chan struct{}, clockInterval *time.Duration, ) (<-chan int64, *am.Machine, *Server, *Client) { - // read env amDbgAddr := os.Getenv("AM_DBG_ADDR") logLvl := am.EnvLogLevel("") diff --git a/pkg/rpc/server.go b/pkg/rpc/server.go index ab6f28d..a63ecbb 100644 --- a/pkg/rpc/server.go +++ b/pkg/rpc/server.go @@ -54,8 +54,10 @@ type Server struct { } // interfaces -var _ serverRpcMethods = &Server{} -var _ clientServerMethods = &Server{} +var ( + _ serverRpcMethods = &Server{} + _ clientServerMethods = &Server{} +) func NewServer( ctx context.Context, addr string, id string, worker *am.Machine, diff --git a/pkg/rpc/shared.go b/pkg/rpc/shared.go index 6feae8f..429d345 100644 --- a/pkg/rpc/shared.go +++ b/pkg/rpc/shared.go @@ -126,10 +126,6 @@ var ( // wrapping error setters -func errResponse(mach *am.Machine, err error) { - mach.AddErr(fmt.Errorf("%w: %w", ErrInvalidResp, err), nil) -} - func errResponseStr(mach *am.Machine, msg string) { mach.AddErr(fmt.Errorf("%w: %s", ErrInvalidResp, msg), nil) } @@ -144,7 +140,6 @@ func errNetwork(mach *am.Machine, err error) { // errAuto detects sentinels from error msgs and wraps. func errAuto(mach *am.Machine, msg string, err error) { - // detect group from text var errGroup error if strings.HasPrefix(err.Error(), "gob: ") { diff --git a/pkg/rpc/utils_test.go b/pkg/rpc/utils_test.go index 1341c93..4118e02 100644 --- a/pkg/rpc/utils_test.go +++ b/pkg/rpc/utils_test.go @@ -5,9 +5,10 @@ import ( "testing" "github.com/lithammer/dedent" + "github.com/stretchr/testify/assert" + am "github.com/pancsta/asyncmachine-go/pkg/machine" "github.com/pancsta/asyncmachine-go/pkg/types" - "github.com/stretchr/testify/assert" ) func assertStates(t *testing.T, m types.MachineApi, expected am.S, diff --git a/pkg/rpc/worker.go b/pkg/rpc/worker.go index 703b398..b869538 100644 --- a/pkg/rpc/worker.go +++ b/pkg/rpc/worker.go @@ -34,8 +34,8 @@ type Worker struct { indexWhen am.IndexWhen indexWhenTime am.IndexWhenTime // TODO indexWhenArgs - indexWhenArgs am.IndexWhenArgs - whenDisposed chan struct{} + // indexWhenArgs am.IndexWhenArgs + whenDisposed chan struct{} } // Worker implements MachineApi @@ -1028,7 +1028,6 @@ func (w *Worker) processWhenTimeBindings(timeBefore am.Time) { // collect all the ticked states all := am.S{} for idx, t := range timeBefore { - // if changed, collect to check if w.clockTime[idx] != t { all = append(all, w.stateNames[idx]) @@ -1037,7 +1036,6 @@ func (w *Worker) processWhenTimeBindings(timeBefore am.Time) { // check all the bindings for all the ticked states for _, s := range all { - for k, binding := range indexWhenTime[s] { // check if the requested time has passed @@ -1133,11 +1131,6 @@ func j(states []string) string { return strings.Join(states, " ") } -// jw joins state names into a single string with a separator. -func jw(states []string, sep string) string { - return strings.Join(states, sep) -} - // disposeWithCtx handles early binding disposal caused by a canceled context. // It's used by most of "when" methods. func disposeWithCtx[T comparable]( @@ -1215,24 +1208,6 @@ func slicesEvery[S1 ~[]E, S2 ~[]E, E comparable](col1 S1, col2 S2) bool { return true } -func slicesFilter[S ~[]E, E any](coll S, fn func(item E, i int) bool) S { - var ret S - for i, el := range coll { - if fn(el, i) { - ret = append(ret, el) - } - } - return ret -} - -func slicesReverse[S ~[]E, E any](coll S) S { - ret := make(S, len(coll)) - for i := range coll { - ret[i] = coll[len(coll)-1-i] - } - return ret -} - func slicesUniq[S ~[]E, E comparable](coll S) S { var ret S for _, el := range coll { diff --git a/pkg/states/ss_basic.go b/pkg/states/ss_basic.go index bc8231a..da4e208 100644 --- a/pkg/states/ss_basic.go +++ b/pkg/states/ss_basic.go @@ -45,9 +45,7 @@ var States = am.Struct{ // Groups of mutually exclusive states. -var ( - GroupConnected = S{Connecting, Connected, Disconnecting, Disconnected} -) +var GroupConnected = S{Connecting, Connected, Disconnecting, Disconnected} // #region boilerplate defs diff --git a/pkg/telemetry/prometheus/prometheus.go b/pkg/telemetry/prometheus/prometheus.go index 40e5ceb..1bd469e 100644 --- a/pkg/telemetry/prometheus/prometheus.go +++ b/pkg/telemetry/prometheus/prometheus.go @@ -1,4 +1,4 @@ -// Package prometheus provides Prometheus metrics for asyncamachine. +// Package prometheus provides Prometheus metrics for asyncmachine. // Metrics are collected from machine's transitions and states. package prometheus @@ -391,7 +391,8 @@ func TransitionsToPrometheus( metrics.RelAmount.Set(float64(relCount)) metrics.RefStatesAmount.Set(float64(stateRefCount)) - mach.Tracers = append(mach.Tracers, &promTracer{m: metrics}) + metrics.tracer = &promTracer{m: metrics} + mach.Tracers = append(mach.Tracers, metrics.tracer) return metrics } diff --git a/pkg/telemetry/telemetry.go b/pkg/telemetry/telemetry.go index 0b1b943..28bc4b1 100644 --- a/pkg/telemetry/telemetry.go +++ b/pkg/telemetry/telemetry.go @@ -86,11 +86,9 @@ type DbgMsgTx struct { func (d *DbgMsgTx) Clock(statesIndex am.S, state string) uint64 { idx := lo.IndexOf(statesIndex, state) return d.Clocks[idx] - } func (d *DbgMsgTx) Is(statesIndex am.S, states am.S) bool { - for _, state := range states { idx := lo.IndexOf(statesIndex, state) //nolint:typecheck if idx == -1 { diff --git a/pkg/types/types.go b/pkg/types/types.go index 33a535b..84b8e55 100644 --- a/pkg/types/types.go +++ b/pkg/types/types.go @@ -9,7 +9,6 @@ import ( // MachineApi is a subset of `pkg/machine#Machine` for alternative // implementations. type MachineApi interface { - // ///// REMOTE // Mutations (remote) diff --git a/tools/debugger/handlers.go b/tools/debugger/handlers.go index 7e56073..ab3ae20 100644 --- a/tools/debugger/handlers.go +++ b/tools/debugger/handlers.go @@ -871,7 +871,6 @@ func (d *Debugger) ToggleFilterState(_ *am.Event) { } func (d *Debugger) SwitchingClientTxState(e *am.Event) { - clientID, _ := e.Args["Client.id"].(string) cursorTx, _ := e.Args["Client.cursorTx"].(int) ctx := d.Mach.NewStateCtx(ss.SwitchingClientTx)