Node

The Node module provides distributed actor capabilities, allowing actors to communicate across machines with location transparency. Messages are automatically serialized for network transport.

Node Identity

Nodes use the format name@host:port for identification, e.g., worker-1@192.168.1.10:9000.

Node Lifecycle

Node.start
String -> Result Unit NodeError
Starts this node with the given identity. Listens for incoming connections.
Node.start "worker-1@192.168.1.10:9000"
Node.stop
() -> Unit
Stops the node, closing all connections gracefully.
Node.name
() -> Option String
Returns the current node's identity if started.
Node.is-running?
() -> Bool
Returns true if the node is running.

Connection Management

Node.connect
String -> Result Unit NodeError
Connects to another node at the given address.
Node.connect "worker-2@192.168.1.11:9000"
Node.disconnect
String -> Unit
Disconnects from the specified node gracefully.
Node.connections
() -> List String
Returns list of all connected node addresses.

Remote Actors

Node.actor
String -> String -> Option Int
Gets a reference to a remote actor by node address and actor name. The returned handle can be used with Actor.send or the <- operator.
match Node.actor "worker-2@192.168.1.11:9000" "counter"
  | Some actor -> actor <- :inc
  | None -> println "Actor not found"
Node.nodes
() -> List String
Returns list of all known nodes (self + connected).

Error Types

type NodeError =
  | ConnectionFailed { address: String, reason: String }
  | ConnectionClosed { address: String }
  | HandshakeFailed { address: String, reason: String }
  | SerializationError { type-name: String, reason: String }
  | NodeNotStarted
  | NodeAlreadyStarted
  | ActorNotFound { name: String, node: String }
  | Timeout { operation: String }
  | InvalidAddress { address: String }
  | BindFailed { address: String, reason: String }