states

package
v0.18.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2026 License: MIT Imports: 3 Imported by: 0

README

/pkg/history

cd /

[!NOTE] asyncmachine-go is a pathless control-flow graph with a consensus (AOP, actor model, state-machine).

Editor Support

This doc file contains tips on how to handle the bulk of boilerplate needed for asyncmachine-go.

Agent Skills

Using LLMs to generate boilerplate is often faster than using am-gen or using live templates. Dirs with SKILL.md files are auto-generated from documentation using the command below. Each skill being a single file can easily be copy-pasted and guarantees the highest compatibility.

# in repo root
./scripts/dep-taskfile.sh
task gen-docs-skills
cp ./docs/editors/skills/* $DEST

Token Usage

Skills are divided based on token usage, each fully contained within a single SKILL.md file.

  • /am-mini ~1.3k tokens - compacted version
  • /am ~2.9k tokens - basic boilerplate
  • /am-cook ~11k tokens - also includes /docs/cookbook.md
  • /am-full ~18k tokens - also includes /docs/manual.md

Live Templates

Live templates expand semantically inside Goland IDE for fast tab-completion.

Handler
  • am
var _ = $SS$.$STATE$
func ($N$ *$HANDLERS$) $STATE$$TYPE$(e *am.Event) $RET$ {
   $END$
}
Name Expression Default value Skip if defined
SS completeSmart() ss
STATE completeSmart() "Foo"
TYPE enum("State","Enter","Exit","End") "State"
RET enum("","bool")
HANDLERS completeSmart()
N goSuggestVariableName() "h"
Handler With Boilerplate
  • am2
var _ = $SS$.$STATE$
func ($N$ *$HANDLERS$) $STATE$$TYPE$(e *am.Event) $RET$ {
    ctx := $N$.Mach.NewStateCtx($STATE$)
    mach := $N$.Mach

    mach.Fork(ctx, e, func() {
        $END$
    })
}
Name Expression Default value Skip if defined
SS completeSmart() ss
STATE completeSmart() "Foo"
TYPE enum("State","Enter","Exit","End") "State"
RET enum("","bool")
HANDLERS completeSmart()
N goSuggestVariableName() "h"
Error Setter
  • amerr
var Err$NAME$ = errors.New("$NAME2$ error")

// AddErr$NAME$ adds [Err$NAME$].
func AddErr$NAME$(
    event *am.Event, mach *am.Machine, err error, args ...am.A,
) am.Result {
    if err == nil {
        return am.Executed
    }
    err = fmt.Errorf("%w: %w", Err$NAME$, err)

    return mach.EvAddErrState(event, ss.Err$NAME$, err, am.OptArgs(args))
}
Name Expression Default value Skip if defined
NAME capitalize(String)
NAME2 camelCase(String) $NAME$
Context Expiration Check
  • ctxexp
if ctx.Err() != nil {
    return // expired
}$END$

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ServerStates contains all the states for the Client machine.
	ServerStates = ssS
	// ServerGroups contains all the state groups for the Client machine.
	ServerGroups = sgS
)
View Source
var ServerSchema = SchemaMerge(

	ss.BasicSchema,
	am.Schema{

		ssS.ErrNetwork: {
			Require: S{am.StateException},
			Remove:  S{ssS.ClientConnected},
		},

		ssS.HandshakeDone: {
			Require: S{ssS.ClientConnected},
			Remove:  S{Exception},
		},

		ssS.Start: {Add: S{ssS.RpcStarting}},
		ssS.Ready: {
			Auto:    true,
			Require: S{ssS.HandshakeDone, ssS.RpcReady},
		},

		ssS.RpcStarting: {
			Require: S{ssS.Start},
			Remove:  sgS.Rpc,
		},
		ssS.RpcAccepting: {
			Require: S{ssS.Start},
			Remove:  sgS.Rpc,
		},
		ssS.RpcReady: {
			Require: S{ssS.Start},
			Remove:  sgS.Rpc,
		},
		ssS.ClientConnected: {
			Require: S{ssS.RpcReady},
		},

		ssS.MetricSync:      {Multi: true},
		ssS.WebSocketTunnel: {},
	})

ServerSchema represents all relations and properties of ClientStates.

Functions

This section is empty.

Types

type ServerGroupsDef

type ServerGroupsDef struct {
	// Rpc is a group for RPC ready states.
	Rpc S
}

ServerGroupsDef contains all the state groups of the Client state machine.

type ServerStatesDef

type ServerStatesDef struct {
	*am.StatesBase

	// Ready - Client is fully connected to the server.
	Ready string

	// Starting listening
	RpcStarting string
	// setting up RPC accepting
	RpcAccepting string
	// RPC is accepting or has accepted connections
	RpcReady string

	// RPC client connected (technically)
	ClientConnected string
	// RPC client fully usable
	HandshakeDone string

	// How many times the client requested a full sync.
	MetricSync string
	// TCP tunneled over websocket
	WebSocketTunnel string

	// inherit from BasicStatesDef
	*ss.BasicStatesDef
}

ServerStatesDef contains all the states of the Client state machine.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL