Skip to main content

init

Function init 

Source
pub async fn init<E: Clock + Storage + Metrics, V: CodecShared>(
    context: E,
    cfg: Config<V::Cfg>,
) -> Result<(Writer<E, V>, Reader<E, V>), Error>
Expand description

Initialize a shared queue and split into writer and reader handles.

§Example

use commonware_macros::select;

let (writer, mut reader) = shared::init(context, config).await?;

// Writer task (clone for multiple producers)
writer.enqueue(item).await?;

// Reader task
loop {
    select! {
        result = reader.recv() => {
            let Some((pos, item)) = result? else { break };
            // Process item...
            reader.ack(pos).await?;
        }
        _ = shutdown => break,
    }
}