Documentation ¶
Overview ¶
Package rpc is a transparent RPC for state machines.
Index ¶
- Constants
- Variables
- func AddErr(mach *am.Machine, msg string, err error)
- func AddErrNetwork(mach *am.Machine, err error)
- func AddErrNoConn(mach *am.Machine, err error)
- func AddErrParams(mach *am.Machine, err error)
- func AddErrResp(mach *am.Machine, err error)
- func AddErrRpcStr(mach *am.Machine, msg string)
- func BindServer(source, target *am.Machine, rpcReady, clientConn string) error
- func BindServerMulti(source, target *am.Machine, rpcReady, clientConn, clientDisconn string) error
- func BindServerRpcReady(source, target *am.Machine, rpcReady string) error
- func ClockFromMsg(before am.Time, msg ClockMsg) am.Time
- func GetClientId(name string) string
- func LogArgs(args am.A) map[string]string
- func Pass(args *A) am.A
- func TrafficMeter(listener net.Listener, fwdTo string, counter chan<- int64, end <-chan struct{})
- type A
- type ArgsGet
- type ArgsLog
- type ArgsMut
- type ArgsPayload
- type Client
- func (c *Client) CallRetryFailedState(e *am.Event)
- func (c *Client) ConnectedState(e *am.Event)
- func (c *Client) ConnectingState(e *am.Event)
- func (c *Client) DisconnectedEnter(e *am.Event) bool
- func (c *Client) DisconnectedState(e *am.Event)
- func (c *Client) DisconnectingEnter(e *am.Event) bool
- func (c *Client) DisconnectingState(e *am.Event)
- func (c *Client) ExceptionState(e *am.Event)
- func (c *Client) Get(ctx context.Context, name string) (*RespGet, error)
- func (c *Client) GetKind() Kind
- func (c *Client) HandshakeDoneEnter(e *am.Event) bool
- func (c *Client) HandshakeDoneState(e *am.Event)
- func (c *Client) HandshakingState(e *am.Event)
- func (c *Client) RemotePushAllTicks(_ *rpc2.Client, clocks []PushAllTicks, _ *Empty) error
- func (c *Client) RemoteSendPayload(_ *rpc2.Client, payload *ArgsPayload, _ *Empty) error
- func (c *Client) RemoteSendingPayload(_ *rpc2.Client, payload *ArgsPayload, _ *Empty) error
- func (c *Client) RemoteSetClock(_ *rpc2.Client, clock ClockMsg, _ *Empty) error
- func (c *Client) RetryingCallEnter(e *am.Event) bool
- func (c *Client) RetryingConnState(e *am.Event)
- func (c *Client) Start() am.Result
- func (c *Client) StartEnd(e *am.Event)
- func (c *Client) StartState(e *am.Event)
- func (c *Client) Stop(waitTillExit context.Context, dispose bool) am.Result
- func (c *Client) WorkerPayloadEnter(e *am.Event) bool
- func (c *Client) WorkerPayloadState(e *am.Event)
- type ClientOpts
- type ClockMsg
- type Empty
- type Event
- type ExceptionHandler
- type HandlerFinal
- type Kind
- type Mux
- func (m *Mux) ClientConnectedState(e *am.Event)
- func (m *Mux) ExceptionState(e *am.Event)
- func (m *Mux) HasClientsEnd(e *am.Event) bool
- func (m *Mux) HealthcheckState(e *am.Event)
- func (m *Mux) NewServerErrEnter(e *am.Event) bool
- func (m *Mux) NewServerErrState(e *am.Event)
- func (m *Mux) Start() am.Result
- func (m *Mux) StartEnd(e *am.Event)
- func (m *Mux) StartState(e *am.Event)
- func (m *Mux) Stop(dispose bool) am.Result
- type MuxNewServer
- type MuxOpts
- type PushAllTicks
- type RespGet
- type RespHandshake
- type RespResult
- type RespSync
- type SendPayloadHandlers
- type Server
- func (s *Server) GetKind() Kind
- func (s *Server) HandshakeDoneEnd(e *am.Event)
- func (s *Server) RemoteAdd(_ *rpc2.Client, args *ArgsMut, resp *RespResult) error
- func (s *Server) RemoteAddNS(_ *rpc2.Client, args *ArgsMut, _ *Empty) error
- func (s *Server) RemoteBye(_ *rpc2.Client, _ *Empty, _ *Empty) error
- func (s *Server) RemoteHandshake(client *rpc2.Client, id *string, _ *Empty) error
- func (s *Server) RemoteHello(client *rpc2.Client, _ *Empty, resp *RespHandshake) error
- func (s *Server) RemoteRemove(_ *rpc2.Client, args *ArgsMut, resp *RespResult) error
- func (s *Server) RemoteSet(_ *rpc2.Client, args *ArgsMut, resp *RespResult) error
- func (s *Server) RemoteSetPushAllTicks(_ *rpc2.Client, val bool, _ *Empty) error
- func (s *Server) RemoteSync(_ *rpc2.Client, sum uint64, resp *RespSync) error
- func (s *Server) RpcReadyEnd(e *am.Event)
- func (s *Server) RpcReadyEnter(e *am.Event) bool
- func (s *Server) RpcReadyState(e *am.Event)
- func (s *Server) RpcStartingEnter(e *am.Event) bool
- func (s *Server) RpcStartingState(e *am.Event)
- func (s *Server) SendPayload(ctx context.Context, payload *ArgsPayload) error
- func (s *Server) Start() am.Result
- func (s *Server) StartEnd(e *am.Event)
- func (s *Server) Stop(dispose bool) am.Result
- type ServerOpts
- type Transition
- type Worker
- func (w *Worker) ActiveStates() am.S
- func (w *Worker) Add(states am.S, args am.A) am.Result
- func (w *Worker) Add1(state string, args am.A) am.Result
- func (w *Worker) Add1NS(state string, args am.A) am.Result
- func (w *Worker) AddErr(err error, args am.A) am.Result
- func (w *Worker) AddErrState(state string, err error, args am.A) am.Result
- func (w *Worker) AddNS(states am.S, args am.A) am.Result
- func (w *Worker) Any(states ...am.S) bool
- func (w *Worker) Any1(states ...string) bool
- func (w *Worker) BindHandlers(handlers any) error
- func (w *Worker) BindTracer(tracer am.Tracer)
- func (w *Worker) Clock(states am.S) am.Clock
- func (w *Worker) Ctx() context.Context
- func (w *Worker) DetachTracer(tracer am.Tracer) bool
- func (w *Worker) Dispose()
- func (w *Worker) Err() error
- func (w *Worker) Export() *am.Serialized
- func (w *Worker) GetLogId() bool
- func (w *Worker) GetLogLevel() am.LogLevel
- func (w *Worker) GetLogger() *am.Logger
- func (w *Worker) GetStruct() am.Struct
- func (w *Worker) Has(states am.S) bool
- func (w *Worker) Has1(state string) bool
- func (w *Worker) Id() string
- func (w *Worker) Index(state string) int
- func (w *Worker) Inspect(states am.S) string
- func (w *Worker) Is(states am.S) bool
- func (w *Worker) Is1(state string) bool
- func (w *Worker) IsClock(clock am.Clock) bool
- func (w *Worker) IsDisposed() bool
- func (w *Worker) IsErr() bool
- func (w *Worker) IsTime(t am.Time, states am.S) bool
- func (w *Worker) Log(msg string, args ...any)
- func (w *Worker) LogLvl(lvl am.LogLevel, msg string, args ...any)
- func (w *Worker) MustParseStates(states am.S) am.S
- func (w *Worker) NewStateCtx(state string) context.Context
- func (w *Worker) Not(states am.S) bool
- func (w *Worker) Not1(state string) bool
- func (w *Worker) ParentId() string
- func (w *Worker) Remove(states am.S, args am.A) am.Result
- func (w *Worker) Remove1(state string, args am.A) am.Result
- func (w *Worker) Set(states am.S, args am.A) am.Result
- func (w *Worker) SetLogId(val bool)
- func (w *Worker) SetLogLevel(level am.LogLevel)
- func (w *Worker) SetLogger(fn am.Logger)
- func (w *Worker) SetLoggerEmpty(level am.LogLevel)
- func (w *Worker) SetLoggerSimple(logf func(format string, args ...any), level am.LogLevel)
- func (w *Worker) StateNames() am.S
- func (w *Worker) StatesVerified() bool
- func (w *Worker) String() string
- func (w *Worker) StringAll() string
- func (w *Worker) Switch(groups ...am.S) string
- func (w *Worker) Sync() am.Time
- func (w *Worker) Tick(state string) uint64
- func (w *Worker) Time(states am.S) am.Time
- func (w *Worker) TimeSum(states am.S) uint64
- func (w *Worker) Tracers() []am.Tracer
- func (w *Worker) When(states am.S, ctx context.Context) <-chan struct{}
- func (w *Worker) When1(state string, ctx context.Context) <-chan struct{}
- func (w *Worker) WhenArgs(state string, args am.A, ctx context.Context) <-chan struct{}
- func (w *Worker) WhenDisposed() <-chan struct{}
- func (w *Worker) WhenErr(ctx context.Context) <-chan struct{}
- func (w *Worker) WhenNot(states am.S, ctx context.Context) <-chan struct{}
- func (w *Worker) WhenNot1(state string, ctx context.Context) <-chan struct{}
- func (w *Worker) WhenTicks(state string, ticks int, ctx context.Context) <-chan struct{}
- func (w *Worker) WhenTicksEq(state string, ticks uint64, ctx context.Context) <-chan struct{}
- func (w *Worker) WhenTime(states am.S, times am.Time, ctx context.Context) <-chan struct{}
- type WorkerTracer
Constants ¶
const ( // EnvAmRpcLogServer enables machine logging for RPC server. EnvAmRpcLogServer = "AM_RPC_LOG_SERVER" // EnvAmRpcLogClient enables machine logging for RPC client. EnvAmRpcLogClient = "AM_RPC_LOG_CLIENT" )
const EnvAmRpcLogMux = "AM_RPC_LOG_MUX"
Variables ¶
var ( ErrInvalidParams = errors.New("invalid params") ErrInvalidResp = errors.New("invalid response") ErrRpc = errors.New("rpc") ErrNoAccess = errors.New("no access") ErrNoConn = errors.New("not connected") ErrNetwork = errors.New("network error") ErrNetworkTimeout = errors.New("network timeout") )
Functions ¶
func AddErr ¶ added in v0.8.0
AddErr detects sentinels from error msgs and calls the proper error setter.
func AddErrNetwork ¶ added in v0.8.0
func AddErrNoConn ¶ added in v0.8.0
func AddErrParams ¶ added in v0.8.0
func AddErrResp ¶ added in v0.8.0
func AddErrRpcStr ¶ added in v0.8.0
func BindServer ¶ added in v0.8.0
BindServer binds RpcReady and ClientConnected with Add/Remove, to custom states.
func BindServerMulti ¶ added in v0.8.0
func BindServerMulti( source, target *am.Machine, rpcReady, clientConn, clientDisconn string, ) error
BindServerMulti binds RpcReady, ClientConnected, and ClientDisconnected. RpcReady is Add/Remove, other two are Add-only to passed multi states.
func BindServerRpcReady ¶ added in v0.8.0
BindServerRpcReady bind RpcReady using Add to a custom multi state.
func GetClientId ¶ added in v0.8.0
GetClientId returns a machine ID from a name. This ID will be used to handshake the server.
Types ¶
type A ¶ added in v0.8.0
type A struct { Id string `log:"id"` Name string `log:"name"` MachTime am.Time Payload *ArgsPayload Addr string `log:"addr"` Err error Method string `log:"addr"` StartedAt time.Time Client *rpc2.Client Dispose bool }
A represents typed arguments of the RPC package.
type ArgsPayload ¶
type Client ¶
type Client struct { *ExceptionHandler Mach *am.Machine Name string // Addr is the address the Client will connect to. Addr string // Worker is a remote am.Machine instance Worker *Worker // Consumer is the optional consumer for deliveries. Consumer *am.Machine CallCount uint64 LogEnabled bool // DisconnCooldown is the time to wait after notifying the server about // disconnecting before actually disconnecting. Default 10ms. DisconnCooldown time.Duration // LastMsgAt is the last received msg from the worker TODO LastMsgAt time.Time // HelloDelay between Connected and Handshaking. Default 0, useful for // rpc/Mux. HelloDelay time.Duration // ReconnectOn decides if the client will try to [RetryingConn] after a // clean [Disconnect]. ReconnectOn bool // ConnTimeout is the maximum time to wait for a connection to be established. // Default 3s. ConnTimeout time.Duration // ConnRetries is the number of retries for a connection. Default 15. ConnRetries int // ConnRetryTimeout is the maximum time to retry a connection. Default 1m. ConnRetryTimeout time.Duration // ConnRetryDelay is the time to wait between retries. Default 100ms. If // ConnRetryBackoff is set, this is the initial delay, and doubles on each // retry. ConnRetryDelay time.Duration // ConnRetryBackoff is the maximum time to wait between retries. Default 3s. ConnRetryBackoff time.Duration // CallTimeout is the maximum time to wait for a call to complete. Default 3s. CallTimeout time.Duration // CallRetries is the number of retries for a call. Default 15. CallRetries int // CallRetryTimeout is the maximum time to retry a call. Default 1m. CallRetryTimeout time.Duration // CallRetryDelay is the time to wait between retries. Default 100ms. If // CallRetryBackoff is set, this is the initial delay, and doubles on each // retry. CallRetryDelay time.Duration // CallRetryBackoff is the maximum time to wait between retries. Default 3s. CallRetryBackoff time.Duration // contains filtered or unexported fields }
func NewClient ¶
func NewClient( ctx context.Context, workerAddr string, name string, stateStruct am.Struct, stateNames am.S, opts *ClientOpts, ) (*Client, error)
NewClient creates a new RPC client and exposes a remote state machine as a remote worker, with a subst of the API under Client.Worker. Optionally takes a consumer, which is a state machine with a WorkerPayload state. See states.ConsumerStates.
func (*Client) CallRetryFailedState ¶ added in v0.8.0
func (*Client) ConnectedState ¶
func (*Client) ConnectingState ¶
func (*Client) DisconnectedState ¶
func (*Client) DisconnectingState ¶
func (*Client) ExceptionState ¶ added in v0.8.0
ExceptionState handles network errors and retries the connection.
func (*Client) HandshakeDoneEnter ¶ added in v0.8.0
func (*Client) HandshakeDoneState ¶
func (*Client) HandshakingState ¶
func (*Client) RemotePushAllTicks ¶ added in v0.8.0
RemotePushAllTicks log all the machine clock's ticks, so all final handlers can be executed in order. Only called by the server.
func (*Client) RemoteSendPayload ¶
RemoteSendPayload receives a payload from the server and triggers WorkDelivered. The Consumer should bind his handlers and handle this state to receive the data.
func (*Client) RemoteSendingPayload ¶ added in v0.8.0
RemoteSendingPayload triggers the WorkerDelivering state, which is an optional indication that the server has started a data transmission to the Client. This payload shouldn't contain the data itself, only the name and token.
func (*Client) RemoteSetClock ¶
RemoteSetClock updates the client's clock. Only called by the server.
func (*Client) RetryingCallEnter ¶ added in v0.8.0
func (*Client) RetryingConnState ¶ added in v0.8.0
RetryingConnState should be set without Connecting in the same tx
func (*Client) Start ¶
Start connects the client to the server and initializes the worker. Results in the Ready state.
func (*Client) StartState ¶ added in v0.8.0
func (*Client) Stop ¶
Stop disconnects the client from the server and disposes the worker.
waitTillExit: if passed, waits for the client to disconnect using the context.
func (*Client) WorkerPayloadEnter ¶ added in v0.8.0
func (*Client) WorkerPayloadState ¶ added in v0.8.0
type ClientOpts ¶ added in v0.8.0
type ClientOpts struct { // PayloadState is a state for the server to listen on, to deliver payloads // to the client. The client adds this state to request a payload from the // worker. Default: am/rpc/states/WorkerStates.SendPayload. Consumer *am.Machine // Parent is a parent state machine for a new Client state machine. See // [am.Opts]. Parent am.Api }
type Event ¶ added in v0.8.0
type Event struct { // Name of the event / handler Name string // Machine is the machine that the event belongs to. Machine am.Api }
Event struct represents a single event of a Mutation within a Transition. One event can have 0-n handlers.
type ExceptionHandler ¶
type ExceptionHandler struct {
*am.ExceptionHandler
}
ExceptionHandler is a shared exception handler for RPC server and client.
func (*ExceptionHandler) ExceptionEnter ¶
func (h *ExceptionHandler) ExceptionEnter(e *am.Event) bool
type HandlerFinal ¶ added in v0.8.0
type HandlerFinal func(e *Event)
type Mux ¶ added in v0.8.0
type Mux struct { *am.ExceptionHandler Mach *am.Machine Name string Addr string Listener net.Listener LogEnabled bool NewServerFn MuxNewServer // The last error returned by NewServerFn. NewServerErr error // contains filtered or unexported fields }
Mux creates a new RPC server for each incoming connection.
func (*Mux) ClientConnectedState ¶ added in v0.8.0
func (*Mux) ExceptionState ¶ added in v0.8.0
func (*Mux) HealthcheckState ¶ added in v0.8.0
func (*Mux) NewServerErrState ¶ added in v0.8.0
func (*Mux) StartState ¶ added in v0.8.0
type MuxNewServer ¶ added in v0.8.0
MuxNewServer is a function to create a new RPC server for each incoming connection.
type PushAllTicks ¶ added in v0.8.0
type RespHandshake ¶
type RespHandshake = am.Serialized
type RespResult ¶
type SendPayloadHandlers ¶ added in v0.8.0
type SendPayloadHandlers struct {
SendPayloadState am.HandlerFinal
}
type Server ¶
type Server struct { *ExceptionHandler Mach *am.Machine // Addr is the address of the server on the network. Addr string DeliveryTimeout time.Duration // PushInterval is the interval for clock updates, effectively throttling // the number of updates sent to the client within the interval window. // 0 means pushes are disabled. Setting to a very small value will make // pushes instant. PushInterval time.Duration // PushAllTicks will push all ticks to the client, enabling client-side final // handlers. TODO implement PushAllTicks bool // Listener can be set manually before starting the server. Listener net.Listener // Conn can be set manually before starting the server. Conn net.Conn // NoNewListener will prevent the server from creating a new listener if // one is not provided, or has been closed. Useful for cmux. NoNewListener bool LogEnabled bool CallCount uint64 // AllowId will limit clients to a specific ID, if set. AllowId string // contains filtered or unexported fields }
Server is an RPC server that can be bound to a worker machine and provide remote access to its states and methods.
func NewServer ¶
func NewServer( ctx context.Context, addr string, name string, worker am.Api, opts *ServerOpts, ) (*Server, error)
NewServer creates a new RPC server, bound to a worker machine. The worker machine has to implement am/rpc/states/WorkerStatesDef interface.
func (*Server) HandshakeDoneEnd ¶
func (*Server) RemoteAddNS ¶
func (*Server) RemoteHandshake ¶
func (*Server) RemoteHello ¶ added in v0.8.0
func (*Server) RemoteRemove ¶
func (*Server) RemoteSetPushAllTicks ¶ added in v0.8.0
func (*Server) RemoteSync ¶
func (*Server) RpcReadyEnd ¶
func (*Server) RpcReadyState ¶
RpcReadyState starts a ticker to compensate for clock push denounces.
func (*Server) RpcStartingEnter ¶ added in v0.8.0
func (*Server) RpcStartingState ¶
func (*Server) SendPayload ¶
func (s *Server) SendPayload(ctx context.Context, payload *ArgsPayload) error
SendPayload sends a payload to the client.
type ServerOpts ¶ added in v0.8.0
type ServerOpts struct { // PayloadState is a state for the server to listen on, to deliver payloads // to the client. The client adds this state to request a payload from the // worker. Default: am/rpc/states/WorkerStates.SendPayload. PayloadState string // Parent is a parent state machine for a new Server state machine. See // [am.Opts]. Parent am.Api }
type Transition ¶ added in v0.8.0
type Transition struct { // Machine is the parent machine of this transition. Machine am.Api // TimeBefore is the machine time from before the transition. TimeBefore am.Time // TimeAfter is the machine time from after the transition. If the transition // has been canceled, this will be the same as TimeBefore. TimeAfter am.Time }
Transition represents processing of a single mutation within a machine.
type Worker ¶
type Worker struct { ID string // TODO remote push Disposed atomic.Bool // contains filtered or unexported fields }
Worker is a subset of `pkg/machine#Machine` for RPC. Lacks the queue and other local methods. Most methods are clock-based, thus executed locally.
func (*Worker) ActiveStates ¶
ActiveStates returns a copy of the currently active states.
func (*Worker) Add ¶
Add activates a list of states in the machine, returning the result of the transition (Executed, Queued, Canceled). Like every mutation method, it will resolve relations and trigger handlers.
func (*Worker) AddErr ¶
AddErr is a dedicated method to add the Exception state with the passed error and optional arguments. Like every mutation method, it will resolve relations and trigger handlers. AddErr produces a stack trace of the error, if LogStackTrace is enabled.
func (*Worker) AddErrState ¶
AddErrState adds a dedicated error state, along with the build in Exception state. Like every mutation method, it will resolve relations and trigger handlers. AddErrState produces a stack trace of the error, if LogStackTrace is enabled.
func (*Worker) AddNS ¶
AddNS is a NoSync method - an efficient way for adding states, as it doesn't wait for, nor transfers a response. Because of which it doesn't update the clock. Use Sync() to update the clock after a batch of AddNS calls.
func (*Worker) Any ¶
Any is group call to Is, returns true if any of the params return true from Is.
machine.StringAll() // ()[Foo:0 Bar:0 Baz:0] machine.Add(S{"Foo"}) // is(Foo, Bar) or is(Bar) machine.Any(S{"Foo", "Bar"}, S{"Bar"}) // false // is(Foo) or is(Bar) machine.Any(S{"Foo"}, S{"Bar"}) // true
func (*Worker) Any1 ¶
Any1 is group call to Is1(), returns true if any of the params return true from Is1().
func (*Worker) BindHandlers ¶ added in v0.8.0
func (*Worker) BindTracer ¶ added in v0.8.0
func (*Worker) Clock ¶
Clock returns current machine's clock, a state-keyed map of ticks. If states are passed, only the ticks of the passed states are returned.
func (*Worker) Dispose ¶
func (w *Worker) Dispose()
Dispose disposes the machine and all its emitters. You can wait for the completion of the disposal with `<-mach.WhenDisposed`.
func (*Worker) Export ¶
func (w *Worker) Export() *am.Serialized
Export exports the machine state: ID, time and state names.
func (*Worker) GetLogLevel ¶ added in v0.8.0
GetLogLevel returns the log level of the machine.
func (*Worker) GetLogger ¶ added in v0.8.0
GetLogger returns the current custom logger function, or nil.
func (*Worker) Has1 ¶
Has1 is a shorthand for Has. It returns true if the passed state is registered in the machine.
func (*Worker) Inspect ¶
Inspect returns a multi-line string representation of the machine (states, relations, clock). states: param for ordered or partial results.
func (*Worker) Is ¶
Is checks if all the passed states are currently active.
machine.StringAll() // ()[Foo:0 Bar:0 Baz:0] machine.Add(S{"Foo"}) machine.TestIs(S{"Foo"}) // true machine.TestIs(S{"Foo", "Bar"}) // false
func (*Worker) Is1 ¶
Is1 is a shorthand method to check if a single state is currently active. See Is().
func (*Worker) IsClock ¶
IsClock checks if the machine has changed since the passed clock. Returns true if at least one state has changed.
func (*Worker) IsDisposed ¶ added in v0.8.0
IsDisposed returns true if the machine has been disposed.
func (*Worker) IsTime ¶
IsTime checks if the machine has changed since the passed time (list of ticks). Returns true if at least one state has changed. The states param is optional and can be used to check only a subset of states.
func (*Worker) LogLvl ¶ added in v0.8.0
LogLvl adds an internal log entry from the outside. It should be used only by packages extending pkg/machine. Use Log instead.
func (*Worker) MustParseStates ¶
MustParseStates parses the states and returns them as a list. Panics when a state is not defined. It's an usafe equivalent of VerifyStates.
func (*Worker) NewStateCtx ¶
NewStateCtx returns a new sub-context, bound to the current clock's tick of the passed state.
Context cancels when the state has been de-activated, or right away, if it isn't currently active.
State contexts are used to check state expirations and should be checked often inside goroutines. TODO log reader
func (*Worker) Not ¶
Not checks if **none** of the passed states are currently active.
machine.StringAll() // -> ()[A:0 B:0 C:0 D:0] machine.Add(S{"A", "B"}) // not(A) and not(C) machine.TestNot(S{"A", "C"}) // -> false // not(C) and not(D) machine.TestNot(S{"C", "D"}) // -> true
func (*Worker) Not1 ¶
Not1 is a shorthand method to check if a single state is currently inactive. See Not().
func (*Worker) Remove ¶
Remove de-activates a list of states in the machine, returning the result of the transition (Executed, Queued, Canceled). Like every mutation method, it will resolve relations and trigger handlers.
func (*Worker) Remove1 ¶
Remove1 is a shorthand method to remove a single state with the passed args. See Remove().
func (*Worker) Set ¶
Set de-activates a list of states in the machine, returning the result of the transition (Executed, Queued, Canceled). Like every mutation method, it will resolve relations and trigger handlers.
func (*Worker) SetLogLevel ¶ added in v0.8.0
SetLogLevel sets the log level of the machine.
func (*Worker) SetLoggerEmpty ¶ added in v0.8.0
SetLoggerEmpty creates an empty logger that does nothing and sets the log level in one call. Useful when combined with am-dbg. Requires LogChanges log level to produce any output.
func (*Worker) SetLoggerSimple ¶ added in v0.8.0
SetLoggerSimple takes log.Printf and sets the log level in one call. Useful for testing. Requires LogChanges log level to produce any output.
func (*Worker) StateNames ¶
StateNames returns a copy of all the state names.
func (*Worker) StatesVerified ¶ added in v0.8.0
StatesVerified returns true if the state names have been ordered using VerifyStates.
func (*Worker) String ¶
String returns a one line representation of the currently active states, with their clock values. Inactive states are omitted. Eg: (Foo:1 Bar:3)
func (*Worker) StringAll ¶
StringAll returns a one line representation of all the states, with their clock values. Inactive states are in square brackets. Eg: (Foo:1 Bar:3)[Baz:2]
func (*Worker) Switch ¶
Switch returns the first state from the passed list that is currently active, making it useful for switch statements.
switch mach.Switch(ss.GroupPlaying) { case "Playing": case "Paused": case "Stopped": }
func (*Worker) Sync ¶
Sync requests fresh clock values from the remote machine. Useful to call after a batch of no-sync methods, eg AddNS.
func (*Worker) Time ¶
Time returns machine's time, a list of ticks per state. Returned value includes the specified states, or all the states if nil.
func (*Worker) TimeSum ¶
TimeSum returns the sum of machine's time (ticks per state). Returned value includes the specified states, or all the states if nil. It's a very inaccurate, yet simple way to measure the machine's time. TODO handle overflow
func (*Worker) When ¶
When returns a channel that will be closed when all the passed states become active or the machine gets disposed.
ctx: optional context that will close the channel when done. Useful when listening on 2 When() channels within the same `select` to GC the 2nd one.
func (*Worker) WhenArgs ¶
WhenArgs returns a channel that will be closed when the passed state becomes active with all the passed args. Args are compared using the native '=='. It's meant to be used with async Multi states, to filter out a specific completion.
func (*Worker) WhenDisposed ¶
func (w *Worker) WhenDisposed() <-chan struct{}
WhenDisposed returns a channel that will be closed when the machine is disposed. Requires bound handlers. Use Machine.Disposed in case no handlers have been bound.
func (*Worker) WhenErr ¶
WhenErr returns a channel that will be closed when the machine is in the Exception state.
ctx: optional context defaults to the machine's context.
func (*Worker) WhenNot ¶
WhenNot returns a channel that will be closed when all the passed states become inactive or the machine gets disposed.
ctx: optional context that will close the channel when done. Useful when listening on 2 WhenNot() channels within the same `select` to GC the 2nd one.
func (*Worker) WhenTicks ¶
WhenTicks waits N ticks of a single state (relative to now). Uses WhenTime underneath.
func (*Worker) WhenTicksEq ¶
WhenTicksEq waits till ticks for a single state equal the given absolute value (or more). Uses WhenTime underneath.
type WorkerTracer ¶
type WorkerTracer struct { *am.NoOpTracer // contains filtered or unexported fields }
WorkerTracer is a tracer for local worker machines (event source).
func (*WorkerTracer) TransitionEnd ¶
func (t *WorkerTracer) TransitionEnd(_ *am.Transition)