package rpc

Import Path
	/pkg/rpc (on go.dev)

Dependency Relation
	imports 26 packages, and imported by 14 packages

Involved Source Files mux.go netmach.go Package rpc is a transparent RPC for state machines. rpc_client.go rpc_server.go
Package-Level Type Names (total 29)
/* sort by: | */
A represents typed arguments of the RPC package. It's a typesafe alternative to [am.A]. Addr string Client *rpc2.Client Dispose bool Err error Id string MachTick uint32 MachTime am.Time Method string Name string Payload *MsgSrvPayload QueueTick uint64 StartedAt time.Time func ParseArgs(args am.A) *A func Pass(args *A) am.A func PassRpc(args *A) am.A
ARpc is a subset of A, that can be passed over RPC. Addr string Dispose bool Err error Id string MachTick uint32 MachTime am.Time Method string Name string Payload *MsgSrvPayload QueueTick uint64 StartedAt time.Time
Client is a type representing an RPC client that interacts with a remote am.Machine instance. Addr is the address the Client will connect to. CallCount uint64 CallRetries is the number of retries for a call. Default 15. CallRetryBackoff is the maximum time to wait between retries. Default 3s. CallRetryDelay is the time to wait between retries. Default 100ms. If CallRetryBackoff is set, this is the initial delay, and doubles on each retry. CallRetryTimeout is the maximum time to retry a call. Default 1m. CallTimeout is the maximum time to wait for a call to complete. Default 3s. ConnRetries is the number of retries for a connection. Default 15. ConnRetryBackoff is the maximum time to wait between retries. Default 3s. ConnRetryDelay is the time to wait between retries. Default 100ms. If ConnRetryBackoff is set, this is the initial delay, and doubles on each retry. ConnRetryTimeout is the maximum time to retry a connection. Default 1m. ConnTimeout is the maximum time to wait for a connection to be established. Default 3s. Consumer is the optional consumer for deliveries. DisconnCooldown is the time to wait after notifying the server about disconnecting before actually disconnecting. Default 10ms. DisconnTimeout time.Duration ExceptionHandler *ExceptionHandler HelloDelay between Connected and Handshaking. Default 0, useful for rpc/Mux. LastMsgAt is the last received msg from the worker TODO LogEnabled bool Mach *am.Machine Name string NetMach is a remote am.Machine instance ReconnectOn decides if the client will try to [RetryingConn] after a clean [Disconnect]. Synchronize machine times for every mutation (within a single sync msg). Only sync selected states. SyncMutationFiltering bool Skip schema synchronization / fetching. Only activete/deactivate (0-1) clock values will be sent. Skip syncing of these states. Args returns a list of registered typed args for a given machine. (*Client) CallRetryFailedState(e *am.Event) (*Client) ConnectedState(e *am.Event) (*Client) ConnectingState(e *am.Event) (*Client) DisconnectedEnter(e *am.Event) bool (*Client) DisconnectedState(e *am.Event) (*Client) DisconnectingEnter(e *am.Event) bool (*Client) DisconnectingState(e *am.Event) ( Client) ExceptionEnter(e *am.Event) bool ExceptionState handles network errors and retries the connection. GetKind returns a kind of the RPC component (server / client). (*Client) HandshakeDoneEnter(e *am.Event) bool (*Client) HandshakeDoneState(e *am.Event) (*Client) HandshakingState(e *am.Event) (*Client) HealthcheckState(e *am.Event) IsPartial is true for NetMachs syncing only a subset of the Net Source's states. RemoteBye is called by the server on a planned disconnect. TODO take a reason / source event? RemoteSchemaChange is called by the server on a source machine schema change. RemoteSendPayload receives a payload from the server and triggers WorkerPayload. The Consumer should bind his handlers and handle this state to receive the data. 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. RemoteUpdate updates the clock of NetMach from a cumulative diff. Only called by the server. RemoteUpdateMutations updates the clock of NetMach from a list of mutations. Only called by the server. (*Client) RetryingCallEnter(e *am.Event) bool RetryingConnState should be set without Connecting in the same tx Start connects the client to the server and initializes the worker. Results in the Ready state. (*Client) StartEnd(e *am.Event) (*Client) StartState(e *am.Event) Stop disconnects the client from the server and disposes the worker. waitTillExit: if passed, waits for the client to disconnect using the context. Sync requests non-diff clock values from the remote machine. Useful to call after a batch of no-sync methods, eg [NetworkMachine.AddNS]. Sync doesn't honor [ClientOpts.SyncMutations] and only returns clock values (so can be used to skip mutation syncing within a period). (*Client) WorkerPayloadEnter(e *am.Event) bool (*Client) WorkerPayloadState(e *am.Event) *Client : github.com/pancsta/asyncmachine-go/pkg/rpc/states.ConsumerHandlers func NewClient(ctx context.Context, netSrcAddr string, name string, netSrcSchema am.Schema, opts *ClientOpts) (*Client, error) func github.com/pancsta/asyncmachine-go/internal/testing.NewRpcClient(t *testing.T, ctx context.Context, addr string, netSrcSchema am.Schema, consumer *am.Machine) *Client func github.com/pancsta/asyncmachine-go/internal/testing.NewRpcTest(t *testing.T, ctx context.Context, netSrc *am.Machine, consumer *am.Machine) (*am.Machine, *Server, *Client) func github.com/pancsta/asyncmachine-go/tools/repl.(*Repl).ListMachines(filters *repl.ListFilters) ([]*Client, error) func github.com/pancsta/asyncmachine-go/internal/testing.RpcGet[G](t *testing.T, c *Client, name server.GetField, defVal G) G func github.com/pancsta/asyncmachine-go/internal/testing.RpcShutdown(ctx context.Context, c *Client, s *Server)
Value string var ClientBye var ClientPushAllTicks var ClientSchemaChange var ClientSendPayload var ClientUpdate var ClientUpdateMutations
Only sync selected states. Consumer is an optional target for the [states.SendPayload] state. Enable client-side mutation filtering by performing relations resolution based on locally active states. Doesn't work with [ClientOpts.NoSchema]. TODO not implemented yet Make this client schema-less (infer an empty one for tracked states). Parent is a parent state machine for a new Client state machine. See [am.Opts]. Skip syncing of these states. Sync machine time for every mutation. Disables [ClientOpts.SyncShallowClocks]. Only activete/deactivate (0-1) clock values will be sent. func NewClient(ctx context.Context, netSrcAddr string, name string, netSrcSchema am.Schema, opts *ClientOpts) (*Client, error)
type ClockUpdateFunc (func)
ExceptionHandler is a shared exception handler for RPC server and client. ExceptionHandler *am.ExceptionHandler (*ExceptionHandler) ExceptionEnter(e *am.Event) bool ExceptionState is a final entry handler for the StateException state. Args: - err error: The error that caused the StateException state. - panic *ExceptionArgsPanic: Optional details about the panic.
Kind of the RCP component. func (*Client).GetKind() Kind func (*Server).GetKind() Kind const KindClient const KindServer
MsgCliHello is the client saying hello to the server. AllowedStates am.S ID of the client saying Hello. Hash of the current schema, or "". Schema is always full and not affected by [MsgCliHello.AllowedStates] or [MsgCliHello.SkippedStates]. ShallowClocks bool SkippedStates am.S SyncMutations bool Client wants to synchronize the schema. func (*Server).RemoteHello(client *rpc2.Client, req *MsgCliHello, resp *MsgSrvHello) error
MsgCliMutation is the client requesting a mutation from the server. Args am.A Event *am.Event States []int func (*Server).RemoteAdd(_ *rpc2.Client, req *MsgCliMutation, resp *MsgSrvMutation) error func (*Server).RemoteAddNS(_ *rpc2.Client, req *MsgCliMutation, _ *MsgEmpty) error func (*Server).RemoteRemove(_ *rpc2.Client, req *MsgCliMutation, resp *MsgSrvMutation) error func (*Server).RemoteSet(_ *rpc2.Client, req *MsgCliMutation, resp *MsgSrvMutation) error
MsgEmpty is an empty message of either the server or client. func (*Client).RemoteBye(_ *rpc2.Client, _ *MsgEmpty, _ *MsgEmpty) error func (*Client).RemoteBye(_ *rpc2.Client, _ *MsgEmpty, _ *MsgEmpty) error func (*Client).RemoteSchemaChange(_ *rpc2.Client, msg *MsgSrvHello, _ *MsgEmpty) error func (*Client).RemoteSendingPayload(_ *rpc2.Client, payload *MsgSrvPayload, _ *MsgEmpty) error func (*Client).RemoteSendPayload(_ *rpc2.Client, payload *MsgSrvPayload, _ *MsgEmpty) error func (*Client).RemoteUpdate(_ *rpc2.Client, update *MsgSrvUpdate, _ *MsgEmpty) error func (*Client).RemoteUpdateMutations(_ *rpc2.Client, updates *MsgSrvUpdateMuts, _ *MsgEmpty) error func (*Server).RemoteAddNS(_ *rpc2.Client, req *MsgCliMutation, _ *MsgEmpty) error func (*Server).RemoteArgs(_ *rpc2.Client, _ *MsgEmpty, resp *MsgSrvArgs) error func (*Server).RemoteBye(_ *rpc2.Client, _ *MsgEmpty, _ *MsgEmpty) error func (*Server).RemoteBye(_ *rpc2.Client, _ *MsgEmpty, _ *MsgEmpty) error func (*Server).RemoteHandshake(client *rpc2.Client, _ *MsgEmpty, _ *MsgEmpty) error func (*Server).RemoteHandshake(client *rpc2.Client, _ *MsgEmpty, _ *MsgEmpty) error func (*Server).RemoteSync(_ *rpc2.Client, _ *MsgEmpty, resp *MsgSrvSync) error
Args []string func (*Server).RemoteArgs(_ *rpc2.Client, _ *MsgEmpty, resp *MsgSrvArgs) error
MsgSrvHello is the server saying hello to the client. Schema am.Schema Serialized *am.Serialized total source states count func (*Client).RemoteSchemaChange(_ *rpc2.Client, msg *MsgSrvHello, _ *MsgEmpty) error func (*Server).RemoteHello(client *rpc2.Client, req *MsgCliHello, resp *MsgSrvHello) error
MsgSrvMutation is the server replying to a mutation request for the client. Mutations *MsgSrvUpdateMuts Result am.Result Update *MsgSrvUpdate func (*Server).RemoteAdd(_ *rpc2.Client, req *MsgCliMutation, resp *MsgSrvMutation) error func (*Server).RemoteRemove(_ *rpc2.Client, req *MsgCliMutation, resp *MsgSrvMutation) error func (*Server).RemoteSet(_ *rpc2.Client, req *MsgCliMutation, resp *MsgSrvMutation) error
MsgSrvPayload is the server sending a payload to the client. Data is the payload data. The Consumer has to know the type. Destination is an optional machine ID that is supposed to receive the payload. Useful when using rpc.Mux. Name is used to distinguish different payload types at the destination. Source is the machine ID that sent the payload. SourceTx is transition ID. Token is a unique random ID for the payload. Autofilled by the server. func (*Client).RemoteSendingPayload(_ *rpc2.Client, payload *MsgSrvPayload, _ *MsgEmpty) error func (*Client).RemoteSendPayload(_ *rpc2.Client, payload *MsgSrvPayload, _ *MsgEmpty) error func (*Server).SendPayload(ctx context.Context, event *am.Event, payload *MsgSrvPayload) error
MsgSrvSync is the server replying to a full sync request from the client. MachTick uint32 QueueTick uint64 Time am.Time func (*Server).RemoteSync(_ *rpc2.Client, _ *MsgEmpty, resp *MsgSrvSync) error
MsgSrvUpdate is the server telling the client about a net source's update. Checksum is the last digit of (TimeSum + QueueTick + MachTick) Indexes of incremented states. MachTick is an incremental diff for the machine tick. TODO optimize: for shallow clocks Active []bool QueueTick is an incremental diff for the queue tick. Clock diffs of incremented states. TODO optimize: []uint16 and send 2 updates when needed func (*Client).RemoteUpdate(_ *rpc2.Client, update *MsgSrvUpdate, _ *MsgEmpty) error
MsgSrvUpdateMuts is like [MsgSrvUpdate] but contains several clock updates (one for each mutation), as well as extra mutation info. CalledStates [][]uint16 TODO mind partially accepted auto states (fake called states). Auto bool Updates []MsgSrvUpdate func (*Client).RemoteUpdateMutations(_ *rpc2.Client, updates *MsgSrvUpdateMuts, _ *MsgEmpty) error
Mux creates a new RPC server for each incoming connection. Addr string Typed arguments struct pointer ArgsPrefix string ExceptionHandler *am.ExceptionHandler The listener used by this Mux, can be set manually before Start(). LogEnabled bool Mach *am.Machine Name string The last error returned by NewServerFn. NewServerFn creates a new instance of Server and is called for every new connection. Source is the state source to expose via RPC. Required if NewServerFn isnt provided. (*Mux) ClientConnectedState(e *am.Event) (*Mux) ExceptionState(e *am.Event) (*Mux) HasClientsEnd(e *am.Event) bool (*Mux) HealthcheckState(e *am.Event) (*Mux) NewServerErrEnter(e *am.Event) bool (*Mux) NewServerErrState(e *am.Event) (*Mux) Start() am.Result (*Mux) StartEnd(e *am.Event) (*Mux) StartEnter(e *am.Event) bool (*Mux) StartState(e *am.Event) (*Mux) Stop(dispose bool) am.Result func NewMux(ctx context.Context, name string, newServerFn MuxNewServerFn, opts *MuxOpts) (*Mux, error)
MuxNewServerFn is a function to create a new RPC server for each incoming connection. func NewMux(ctx context.Context, name string, newServerFn MuxNewServerFn, opts *MuxOpts) (*Mux, error)
Typed arguments struct pointer ArgsPrefix string Parent is a parent state machine for a new Mux state machine. See [am.Opts]. func NewMux(ctx context.Context, name string, newServerFn MuxNewServerFn, opts *MuxOpts) (*Mux, error)
NetMachConn is a mutation interface for NetworkMachine instances. It's meant to be (optionally) injected by whatever creates network machines, so they can communicate with the server (or another source). ( NetMachConn) Call(ctx context.Context, method ServerMethod, args any, resp any) bool ( NetMachConn) Notify(ctx context.Context, method ServerMethod, args any) bool func NewNetworkMachine(ctx context.Context, id string, conn NetMachConn, schema am.Schema, stateNames am.S, parent *am.Machine, tags []string, filterMutations bool) (*NetworkMachine, *NetMachInternal, error)
NetMachInternal are internal methods of a NetworkMachine instance returned by the constructor. (*NetMachInternal) Lock() (*NetMachInternal) Unlock() (*NetMachInternal) UpdateClock(now am.Time, qTick uint64, machTick uint32) *NetMachInternal : sync.Locker func NewNetworkMachine(ctx context.Context, id string, conn NetMachConn, schema am.Schema, stateNames am.S, parent *am.Machine, tags []string, filterMutations bool) (*NetworkMachine, *NetMachInternal, error)
NetworkMachine is a subset of `pkg/machine#Machine` for RPC. Lacks the queue and other local methods. Most methods are clock-based, thus executed locally. NetworkMachine implements [am.Api]. If true, the machine will print all exceptions to stdout. Default: true. Requires an ExceptionHandler binding and Machine.PanicToException set. ActiveStates returns a copy of the currently active states. Add is [am.Api.Add]. Add1 is [am.Api.Add1]. Add1NS is a single state version of AddNS. AddBreakpoint is [am.Api.AddBreakpoint]. AddBreakpoint1 is [am.Api.AddBreakpoint1]. AddErr is [am.Api.AddErr]. AddErrState is [am.Api.AddErrState]. 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. Any is [am.Api.Any]. Any1 is [am.Api.Any1]. BindHandlers is [am.Api.BindHandlers]. NetworkMachine supports only pipe handlers (final ones, without negotiation). BindTracer is [am.Machine.BindTracer]. NetworkMachine tracers cannot mutate synchronously, as network machines don't have a queue and WILL deadlock when nested. CanAdd is [am.Api.CanAdd]. CanAdd1 is [am.Api.CanAdd1]. CanRemove is [am.Api.CanRemove]. CanRemove1 is [am.Api.CanRemove1]. 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. Ctx return worker's root context. DetachHandlers is [am.Api.DetachHandlers]. DetachTracer is [am.Api.DetachTracer]. Dispose disposes the machine and all its emitters. You can wait for the completion of the disposal with `<-mach.WhenDisposed`. Err returns the last error. EvAdd is [am.Api.EvAdd]. EvAdd1 is [am.Api.EvAdd1]. EvAddErr is [am.Api.EvAddErr]. EvAddErrState is [am.Api.EvAddErrState]. EvRemove is [am.Api.EvRemove]. EvRemove1 is [am.Api.EvRemove1]. EvToggle is [am.Api.EvToggle]. EvToggle1 is [am.Api.EvToggle1]. Export exports the machine state: id, time and state names. Groups is [am.Api.Groups]. Has is [am.Api.Has]. Has1 is [am.Api.Has1]. HasHandlers is [am.Api.HasHandlers]. Id returns the machine's id. (*NetworkMachine) Index(states am.S) []int Index1 returns the index of a state in the machine's StateNames() list. Inspect returns a multi-line string representation of the machine (states, relations, clock). states: param for ordered or partial results. Is is [am.Api.Is]. Is1 is [am.Api.Is1]. IsClock is [am.Api.IsClock]. IsDisposed returns true if the machine has been disposed. IsErr is [am.Api.IsErr]. IsTime is [am.Api.IsTime]. Log logs is a local logger. MachineTick is [am.Api.MachineTick]. MustParseStates parses the states and returns them as a list. Panics when a state is not defined. It's an usafe equivalent of VerifyStates. 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 Not is [am.Api.Not]. Not1 is [am.Api.No1]. OnDispose is [am.Api.OnDispose]. ParentId returns the id of the parent machine (if any). ParseStates is [am.Api.ParseStates]. QueueLen is [am.Api.QueueLen]. QueueTick is [am.Api.QueueTick]. RemoteId returns the ID of the remote state machine. Remove is [am.Api.Remove]. Remove1 is [am.Api.Remove1]. Schema returns a copy of machine's state structure. (*NetworkMachine) SemLogger() am.SemLogger Set is [am.Api.Set]. StateNames returns a copy of all the state names. (*NetworkMachine) StateNamesMatch(re *regexp.Regexp) am.S StatesVerified returns true if the state names have been ordered using VerifyStates. String returns a one line representation of the currently active states, with their clock values. Inactive states are omitted. Eg: (Foo:1 Bar:3) 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] Switch is [am.Api.Switch]. Tags returns machine's tags, a list of unstructured strings without spaces. Tick returns the current tick for a given state. Time returns machine's time, a list of ticks per state. Returned value includes the specified states, or all the states if nil. Toggle is [am.Api.Toggle]. Toggle1 is [am.Api.Toggle1]. Tracers is [am.Api.Tracers]. Transition is [am.Machine.Transition]. WasClock is [am.Api.WasClock]. WasTime is [am.Api.WasTime]. When is [am.Api.When]. When1 is an alias to When() for a single state. See When. 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. ctx: optional context that will close the channel when done. 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. WhenErr is [am.Api.WhenErr]. 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 early. WhenNot1 is an alias to WhenNot() for a single state. See WhenNot. WhenQuery returns a channel that will be closed when the passed [clockCheck] function returns true. [clockCheck] should be a pure function and non-blocking.` ctx: optional context that will close the channel early. (*NetworkMachine) WhenQueue(tick am.Result) <-chan struct{} WhenTicks waits N ticks of a single state (relative to now). Uses WhenTime underneath. ctx: optional context that will close the channel early.moon WhenTime returns a channel that will be closed when all the passed states have passed the specified time. The time is a logical clock of the state. Machine time can be sourced from [Machine.Time](), or [Machine.Clock](). ctx: optional context that will close the channel early. WhenTime1 waits till ticks for a single state equal the given value (or more). ctx: optional context that will close the channel early. *NetworkMachine : github.com/pancsta/asyncmachine-go/pkg/machine.Api *NetworkMachine : expvar.Var *NetworkMachine : fmt.Stringer func NewNetworkMachine(ctx context.Context, id string, conn NetMachConn, schema am.Schema, stateNames am.S, parent *am.Machine, tags []string, filterMutations bool) (*NetworkMachine, *NetMachInternal, error) func github.com/pancsta/asyncmachine-go/tools/repl.(*Repl).NetMach(machId string) *NetworkMachine
optional channel to send the address to, once ready optional dir path to save the address file as addrDir/mach-id.addr optional typed args instance. Requires ArgsPrefix optional prefix for typesafe args. Requires Args. optional channel to send err to, once ready func MachRepl(mach am.Api, addr string, opts *ReplOpts) error
SendPayloadState am.HandlerFinal
Server is an RPC server that can be bound to a worker machine and provide remote access to its states and methods. Addr is the address of the server on the network. AllowId will limit clients to a specific ID, if set. Typed arguments struct value with defaults Typed arguments prefix in a resulting [am.A] map. CallCount uint64 Conn can be set manually before starting the server. DeliveryTimeout is a timeout for SendPayload to the client. ExceptionHandler *ExceptionHandler Listener can be set manually before starting the server. LogEnabled bool Mach *am.Machine NoNewListener will prevent the server from creating a new listener if one is not provided or has been closed. Useful for cmux. 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. Source is a state Source, either a local or remote RPC worker. (*Server) ClientId() string ( Server) ExceptionEnter(e *am.Event) bool ExceptionState is a final entry handler for the StateException state. Args: - err error: The error that caused the StateException state. - panic *ExceptionArgsPanic: Optional details about the panic. GetKind returns a kind of RPC component (server / client). (*Server) HandshakeDoneEnd(e *am.Event) (*Server) RemoteAdd(_ *rpc2.Client, req *MsgCliMutation, resp *MsgSrvMutation) error (*Server) RemoteAddNS(_ *rpc2.Client, req *MsgCliMutation, _ *MsgEmpty) error (*Server) RemoteArgs(_ *rpc2.Client, _ *MsgEmpty, resp *MsgSrvArgs) error RemoteBye means the client says goodbye and will disconnect shortly. (*Server) RemoteHandshake(client *rpc2.Client, _ *MsgEmpty, _ *MsgEmpty) error (*Server) RemoteHello(client *rpc2.Client, req *MsgCliHello, resp *MsgSrvHello) error (*Server) RemoteRemove(_ *rpc2.Client, req *MsgCliMutation, resp *MsgSrvMutation) error (*Server) RemoteSet(_ *rpc2.Client, req *MsgCliMutation, resp *MsgSrvMutation) error (*Server) RemoteSync(_ *rpc2.Client, _ *MsgEmpty, resp *MsgSrvSync) error (*Server) RpcReadyEnter(e *am.Event) bool RpcReadyState starts a ticker to compensate for clock push debounces. (*Server) RpcStartingEnter(e *am.Event) bool (*Server) RpcStartingState(e *am.Event) SendPayload sends a payload to the client. It's usually called by a handler for SendPayload. [event] is optional. Start starts the server, optionally creating a Listener (if Addr provided). Results in either RpcReady or Exception. (*Server) StartEnd(e *am.Event) Stop stops the server, and optionally disposes resources. func NewServer(ctx context.Context, addr string, name string, netSrcMach am.Api, opts *ServerOpts) (*Server, error) func github.com/pancsta/asyncmachine-go/internal/testing.NewRpcTest(t *testing.T, ctx context.Context, netSrc *am.Machine, consumer *am.Machine) (*am.Machine, *Server, *Client) func github.com/pancsta/asyncmachine-go/internal/testing.RpcShutdown(ctx context.Context, c *Client, s *Server)
Value string func NetMachConn.Call(ctx context.Context, method ServerMethod, args any, resp any) bool func NetMachConn.Notify(ctx context.Context, method ServerMethod, args any) bool var ServerAdd var ServerAddNS var ServerArgs var ServerBye var ServerHandshake var ServerHello var ServerLog var ServerRemove var ServerSet var ServerSync
Typed arguments struct pointer ArgsPrefix string Parent is a parent state machine for a new Server state machine. See [am.Opts]. PayloadState is a state for the server to listen on, to deliver payloads to the client. The client activates this state to request a payload from the worker. Default: am/rpc/states/WorkerStates.SendPayload. func NewServer(ctx context.Context, addr string, name string, netSrcMach am.Api, opts *ServerOpts) (*Server, error)
Package-Level Functions (total 23)
AddErr detects sentinels from error msgs and calls the proper error setter. TODO also return error for compat
func AddErrNetwork(e *am.Event, mach *am.Machine, err error)
func AddErrNoConn(e *am.Event, mach *am.Machine, err error)
func AddErrParams(e *am.Event, mach *am.Machine, err error)
func AddErrResp(e *am.Event, mach *am.Machine, err error)
func AddErrRpcStr(e *am.Event, mach *am.Machine, msg string)
BindServer binds RpcReady and ClientConnected with Add/Remove, to custom states.
BindServerMulti binds RpcReady, ClientConnected, and ClientDisconnected. RpcReady is Add/Remove, the other two are Add-only to passed multi states.
BindServerRpcReady bind RpcReady using Add to a custom multi state.
Checksum calculates a short checksum of current machine time and ticks.
GetClientId returns an RPC Client machine ID from a name. This ID will be used to handshake the server.
LogArgs is an args logger for A.
MachRepl sets up a machine for a REPL connection, which allows for mutations, like any other RPC connection. See [/tools/cmd/arpc] for usage. This function is considered a debugging helper and can panic. addr: address to listen on, default to 127.0.0.1:0 addrDir: optional dir path to save the address file as addrDir/mach-id.addr addrCh: optional channel to send the address to, once ready errCh: optional channel for errors
MachReplEnv sets up a machine for a REPL connection in case AM_REPL_ADDR env var is set. See MachRepl.
NewClient creates a new RPC client and exposes a remote state machine as a remote worker, with a subst of the API under Client.NetMach. Optionally takes a consumer, which is a state machine with a WorkerPayload state. See states.ConsumerStates.
TODO optimize with msgpack
NewMux initializes a Mux instance to handle RPC server creation for incoming connections with the given parameters. newServerFn: when nil, [Mux.Source] needs to be set manually before calling [Mux.Start].
NewNetworkMachine creates a new instance of a NetworkMachine.
NewServer creates a new RPC server, bound to a worker machine. The source machine has to implement [states.NetSourceStatesDef] interface.
ParseArgs extracts A from [am.Event.Args][APrefix].
Pass prepares [am.A] from A to pass to further mutations.
PassRpc prepares [am.A] from A to pass over RPC.
TrafficMeter measures the traffic of a listener and forwards it to a destination. Results are sent to the [counter] channel. Useful for testing and benchmarking.
Package-Level Constants (total 10)
const APrefix = "am_rpc"
EnvAmReplAddr is a REPL address to listen on. "1" expands to 127.0.0.1:0.
EnvAmReplDir is a dir path to save the address file as $AM_REPL_DIR/mach-id.addr. Optional.
EnvAmRpcDbg enables env-based debugging for RPC components.
EnvAmRpcLogClient enables machine logging for RPC client.
EnvAmRpcLogMux enables machine logging for RPC multiplexers.
EnvAmRpcLogServer enables machine logging for RPC server.
const KindClient Kind = "client"
const KindServer Kind = "server"
const PrefixNetMach = "rnm-"