Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dyn std::ops::FnMut() cannot be sent between threads safely #20

Open
alopatindev opened this issue Jun 2, 2020 · 0 comments
Open

dyn std::ops::FnMut() cannot be sent between threads safely #20

alopatindev opened this issue Jun 2, 2020 · 0 comments

Comments

@alopatindev
Copy link

Thanks for this crate. It'd be handy to use it in async programs.

run: Box<dyn (FnMut() -> ()) + 'a> causes

`dyn std::ops::FnMut()` cannot be sent between threads safely

in the following example:

use job_scheduler::{Job, JobScheduler};
use std::time::Duration;
use tokio::time::delay_for;

#[tokio::main]
async fn main() {
    let mut scheduler = JobScheduler::new();
    scheduler.add(Job::new("1/1 * * * * * *".parse().unwrap(), || {
        dbg!("hello");
    }));
    tokio::spawn(async move {
        loop {
            scheduler.tick();
            delay_for(Duration::from_millis(500)).await;
        }
    })
    .await
    .unwrap();
}
[package]
name = "hello_job_scheduler"
version = "0.1.0"
edition = "2018"

[dependencies]
job_scheduler = "1"
tokio = { version = "0.2", features = ["rt-threaded", "macros", "time"]}
alopatindev added a commit to alopatindev/job_scheduler that referenced this issue Jun 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant