mvniekerk / tokio-cron-scheduler

Schedule tasks on Tokio using cron-like annotation
Apache License 2.0
453 stars 54 forks source link

Examples are outdated #31

Closed PaulDotSH closed 1 year ago

PaulDotSH commented 1 year ago

Hi, the examples from the README are outdated. Replacing the sched init line with this

let mut sched = JobScheduler::new().await.unwrap();

Lets us compile the code, however the behavior isn't expected, the program exits instead of waiting

Example code

    let mut sched = JobScheduler::new().await.expect("mata");

    let jja = Job::new_repeated_async(Duration::from_secs(7), |_uuid, _l| Box::pin(async move {
        println!("{:?} I'm repeated async every 7 seconds", chrono::Utc::now());
    })).unwrap();
    sched.add(jja).await;
    #[cfg(feature = "signal")]
    sched.shutdown_on_ctrl_c();
    sched.set_shutdown_handler(Box::new(|| {
        Box::pin(async move {
            println!("Shut down done");
        })
    }));
    sched.start().await;
mvniekerk commented 1 year ago

Yes you're right it won't wait.

mvniekerk commented 1 year ago

Updated. Thanks @PaulDotSH for the suggestion!