Skip to content

Static DB pool using tokio::sync::OnceCell #2663

Answered by jplatte
tayleighr asked this question in Q&A
Discussion options

You must be logged in to vote

I think you're misunderstanding a few things, but your conclusion is correct.

First off, both axum and tokio's OnceCell type don't interact with the tokio runtime at all, i.e. they can be used inside any async runtime (axum::serve does make use of hyper-utils tokio integration, but you serve connections and pass them to axum differently). So even if the runtime that runs the async closure to initialize the cell was different from the one that you use to run hyper/axum in, that wouldn't be a problem.

To your actual question, there is nothing inherently wrong with sharing state with statics instead of axum's State. We recommend State because it's easy and has the advantage of allowing multi…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@tayleighr
Comment options

@jplatte
Comment options

Answer selected by tayleighr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants