Module pipe

Module pipe 

Source
Expand description

§Pipe streams to backends

This backend allows you to pipe tasks from any stream into another backend. It is useful for connecting different backends together, such as piping tasks from a cron stream into a database backend, or transforming and forwarding tasks between systems.

§Example

#[tokio::main]
async fn main() {
    let stm = stream::iter(0..10).map(|s| Ok::<_, std::io::Error>(s));

    let in_memory = JsonStorage::new_temp().unwrap();
    let backend = stm.pipe_to(in_memory);

    async fn task(task: u32, ctx: WorkerContext) -> Result<(), BoxDynError> {
        tokio::time::sleep(Duration::from_secs(1)).await;
        Ok(())
    }

    let worker = WorkerBuilder::new("rango-tango")
        .backend(backend)
        .on_event(|_ctx, ev| {
            println!("On Event = {:?}", ev);
        })
        .build(task);
    worker.run().await.unwrap();
}

This example pipes a stream of numbers into an in-memory backend and processes them with a worker.

See also:

Structs§

Pipe
A generic pipe that wraps a Stream and passes it to a backend

Enums§

PipeError
Error encountered while piping streams

Traits§

PipeExt
Represents utility for piping streams into a backend