-
Notifications
You must be signed in to change notification settings - Fork 55
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
Can't run an async function that operate MySQL via Connection Pool. #8
Comments
Hi @Chcp |
@mvniekerk The source code is simple, there is the repository, it can't be compiled because of errors. |
I had a quick look. Seems like the linked list implementation used somewhere in the sqlx crate was not marked as Sync / Send... This is bad news for your implementation. |
Hi @mvniekerk |
Hi
Any work around is appreciated. |
An easy workaround is to send a message in the job, using mpsc: sched.add(Job::new_async("1/10 * * * * *", move |_uuid, _l| {
let tx = tx.clone();
Box::pin(async move {
tx.send(1).await.unwrap();
}
})}).unwrap()).unwrap(); And then do the action in another thread: let (tx, mut rx) = mpsc::channel::<u8>(1);
tokio::spawn(async move {
loop {
for _ in rx.recv().await {
do_whatever_wasnt_possible_before().await;
}
}
}); This works for me at least. |
It is a possible way, I will try this. Thanks for sharing code. |
Thank you @saabye-io - that's about the only solution right now is if you "escape" out of sync+send land into non-sync+send land using mpsc. |
Hi @mvniekerk,
Thank you for offering the wonderful project "tokio-cron-scheduler".
I use tokio-cron-scheduler run an async function to write MySQL, but there are some errors, would you like to have a look at those, thank you very much.
Code:
Compile errors:
More details:
The text was updated successfully, but these errors were encountered: