Module asynchronous

Source
Expand description

Generic asynchronous implementation.

This module contains generic definitions for functions using arbitrary asynchronous runtimes. The crossmist::tokio and crossmist::smol modules provides type and functions definitions for their respective runtimes. You should probably use those.

§Channels

Asynchronous channels work just like synchronous channels except that you need to add .await to each blocking call. Synchronous and asynchronous channels can be converted to each other. This might be useful if you use tokio/smol in the parent process but use synchronous code in the child. In this case, you would create a channel using crossmist::channel and convert one side to an asynchronous one.

§Processes

To start a child process, you use any of the spawn_tokio and spawn_smol methods generated by #[func]:

#[func]
fn my_process() {
    ...
}

let child = my_process.spawn_tokio().await?;
// let child = my_process.spawn_smol().await?;

Note that you can use these methods on both synchronous and asynchronous functions, e.g. the following works too:

#[func(tokio)]
async fn my_process() {
    ...
}

let child = my_process.spawn_tokio().await?;

Structs§

Child
A subprocess.
Duplex
A side of a bidirectional channel.
KillHandle
A handle that allows to kill the process.
Receiver
The receiving side of a unidirectional channel.
Sender
The transmitting side of a unidirectional channel.

Traits§

AsyncStream
Runtime-dependent stream implementation.

Functions§

channel
Create a unidirectional channel.
duplex
Create a bidirectional channel.