logo   async
machine.dev

/examples/wasm/README.md

A simple example of WASM interop and communication between two distributed async state machines.

Actors (server):

  • server-foo main state machine
    • RPC server (WS)
  • aRPC client (WS / TCP)
    • rc-server-bar network mach

Actors (browser):

  • browser-bar UI state machine
    • RPC server (WS / TCP over WS)
  • aRPC client (WS)
    • rnm-browser-foo network mach
    • browser-foo net handler mach

Implementation

net/rpc, cenkalti/rpc2, and coder/websocket with TCP-over-WebSocket bridged using /tools/cmd/am-relay.

logical diagram

Debugging

Both server-foo and browser-bar connect to a single am-dbg instance running on the server and can be stepped through, with context from all the other machines.

Both server-foo and browser-bar expose REPLs.

am-dbg WASM

Interactively use the TUI debugger with data pre-generated by this example:

go run github.com/pancsta/asyncmachine-go/tools/cmd/am-dbg@latest \
  --import-data https://assets.asyncmachine.dev/am-dbg-exports/wasm.gob.br \
  mach://server-foo

Machine Diagrams

am-vis --bird --render-detailed-pipes --render-pipes render-dump tmp/am-dbg-dump.gob.br

am-dbg WASM

Extended Network Diagram

# .env
AM_RPC_LOG_SERVER=1
AM_RPC_LOG_CLIENT=1
AM_RPC_LOG_MUX=1
AM_RPC_DBG=1

am-vis --bird --render-detailed-pipes --render-pipes render-dump tmp/am-dbg-dump.gob.br

Click to expand the diagram

am-dbg WASM

TODO bug: RPC conns and some parent rels not rendered

Commands

$ task --list-all

task: Available tasks for this project:
* build:            Development build
* build-prod:       Optimized build
* deps:             List dependencies in deps.md
* deps-graph:       Render dependencies graph in deps-graph.svg
* repl:             Start REPL for both server and browser
* start:            Build and start server