pub struct Mesh { /* private fields */ }Expand description
Represents a mesh::Node with the ability to spawn new processes that can communicate with any other process belonging to the same mesh.
§Process creation
A Mesh instance can spawn new processes with an initial communication
channel associated with the mesh. All processes originating from the same
mesh can potentially communicate and exchange channels with each other.
Each spawned process can be configured differently via ProcessConfig.
Processes are created with Mesh::launch_host.
let mesh = Mesh::new("remote_mesh".to_string()).unwrap();
let (send, recv) = mesh::channel();
mesh.launch_host(ProcessConfig::new("test"), recv).await.unwrap();
send.send(String::from("message for new process"));Implementations§
Source§impl Mesh
impl Mesh
Sourcepub async fn launch_host<T: 'static + MeshField + Send>(
&self,
config: ProcessConfig,
initial_message: T,
) -> Result<i32>
pub async fn launch_host<T: 'static + MeshField + Send>( &self, config: ProcessConfig, initial_message: T, ) -> Result<i32>
Spawns a new host in the mesh with the provided configuration and initial message.
The initial message will be provided to the closure passed to
try_run_mesh_host().
Returns the process ID of the launched host.
Sourcepub async fn shutdown(self)
pub async fn shutdown(self)
Shutdown the mesh and wait for any spawned processes to exit.
The Mesh instance is no longer usable after shutdown.
Sourcepub async fn listen<T: 'static + MeshField + Send>(
&self,
path: &Path,
) -> Result<Listener<T>>
pub async fn listen<T: 'static + MeshField + Send>( &self, path: &Path, ) -> Result<Listener<T>>
Listen for mesh connections on a Unix socket.
Returns a Listener<T> that yields items from connecting clients.
Each client gets a Sender<T> bridged to this listener’s queue.
Dropping the Listener stops accepting new connections.
§Security
The socket at path is an external entry point for other local
processes to join the mesh. On Unix, path must reside in a
directory accessible only to the intended user (e.g. mode 0700).
On Windows, the socket’s parent directory should be ACL’d to
restrict access. Any local user who can connect to the socket can
join the mesh.