SQLx from a function? #440
-
Hey there! I wanted to call to an SQLx database from within an mlua async function. Biggest issue I came across was that I think mlua uses futures-utils and tokio based sqlx straight up refused to work, and async-std based sqlx freezes the compiler, and doesn't return anything. Is there any way to run a tokio or async-std based library in mlua async functions? A large amount of my codebase depends on lua and this is a hard need... |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 15 replies
-
Solution for those seeking is to use Tokio's handle. Possible through a static this stackoverflow thread can be helpful: https://stackoverflow.com/questions/61292425/how-to-run-an-asynchronous-task-from-a-non-main-thread-in-tokio |
Beta Was this translation helpful? Give feedback.
-
Do you use module mode? #[tokio::main]
async fn main() {} |
Beta Was this translation helpful? Give feedback.
Solution for those seeking is to use Tokio's handle. Possible through a static
once_cell
. And then spawn an async thread to do the task you want.this stackoverflow thread can be helpful: https://stackoverflow.com/questions/61292425/how-to-run-an-asynchronous-task-from-a-non-main-thread-in-tokio