zino-rs / zino

Next-generation framework for composable applications in Rust.
https://crates.io/crates/zino
MIT License
762 stars 52 forks source link

Spawn async jobs in ntex #119

Open photino opened 3 months ago

photino commented 3 months ago

How can we run async jobs in the background? I have tried

System::new("scheduler")
    .system()
    .arbiter()
    .spawn(Box::pin(async move {
        loop {
            scheduler.tick().await;

            // Cannot use `std::thread::sleep` because it blocks the Tokio runtime.
            time::sleep(scheduler.time_till_next_job()).await;
        }
    }));

But it does not work as expected.

Also see https://github.com/ntex-rs/ntex/issues/335#issuecomment-2071434629