Other tips
utoipa just serve the openapi.json
channels
std::mpsc::Sender
is !Sync (which means you need to wrap it with a Mutex or similar) where crossbeam::channel::Sender
is Sync.
Other than the perforance gains, seems like crossbeam
is status quo.
accessing the tokio’s runtime from other threads
we don’t want multiple runtimes in one app.
use std::thread; #[tokio::main] async fn main() { thread::spawn(move ||{ async_function().await; }); } async fn async_function() { }
but there might be situations that we want to fun async functions inside our dedicated thread.
in that case you get the handle of the runtime and use that
use tokio::runtime::Handle; let handle = Handle::current(); handle.spawn(async move{ async_function().await; });
other small things
const
or static
Almost always use const
. I guess when const
it lives in the binary, on the otherhand when it’s a static
it has a memory assigned and could be modified through unsafe
operations.