How to initilize Postgres Pool in lazy_static

I've seen this example but it doesn't actually work.

I've tried with bb8 and r2d2 and nothing seems to work. bb8 requires initializing the Pool with async which means it won't work with lazy_static. I'm leaving this question vague on details because I would like suggestions on the best way to do this overall.

You can use futures::block_on() to run async code in a non-async context.

Using block_on in a lazy_static is generally a bad idea because the initialization is going to run inside the async context even though the function is sync. How about using the tokio::sync::OnceCell type instead of lazy_static?

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.