Examples

This folder contains runnable integration examples demonstrating type-safe distributed messaging with the distribute library.

These examples use the new GlobalSubject with integrated codecs, showing compile-time type safety for cross-node communication.

Prerequisites

Available Examples

1. two_nodes/ — Basic Type-Safe Messaging

Demonstrates:

Run:

./examples/two_nodes/integration_test.sh

2. two_nodes_app/ — SWIM Membership + Type-Safe Messaging

Demonstrates:

Run:

./examples/two_nodes_app/scripts/run_integration.sh

3. typed_messaging/ — Advanced Type-Safe Examples

Demonstrates:

Run:

# Terminal 1
gleam run -m examples/typed_messaging/typed_node_a

# Terminal 2
gleam run -m examples/typed_messaging/typed_node_b

Example of receiving a message:

case global.receive(my_global, 5_000) {
  Ok(msg) -> // use msg
  Error(_) -> // timeout or decode error
}

What’s New in v2.0

All examples now use:

Integration Tests

The two_nodes/ directory also contains additional integration test scripts:

Search Document