Function async_gen::gen

source ·
pub fn gen<Y, R, Fut>(fut: impl FnOnce(Yield<Y>) -> Fut) -> AsyncGen<Y, Fut>where
    Fut: Future<Output = (Yield<Y>, R)>,
Expand description

Creates a new generator, which implements the AsyncGenerator trait.

Also see gen! macro for more details.

Examples

use async_gen::{gen, AsyncGenerator};

fn create_generator() -> impl AsyncGenerator {
    gen(|mut c| async {
        c.yield_(42).await;
        return (c, "foo");
    })
}