#done
5 messages · Page 1 of 1 (latest)
from what I understand .accept().await blocks the thread until a connection is received
the idea is to call this every iteration of my main/server loop
alternatively I could have spawned a thread which is what i had previously with .accept() but that caused issues because evertying had to be inside of arcs and mutexes slowing main/serverloop down
.accept().await will block the task, yes, but not the thread. Other spawned tasks on the tokio runtime will continue.
If you want to do "return a connection if there is one immediately available, otherwise just nothing", then you can use futures::FutureExt::now_or_never, e.g. ```rs
if let Some(Ok(connection)) = self.listener.accept().now_or_never() {
// ...
}
https://docs.rs/futures/0.3.29/futures/future/trait.FutureExt.html#method.now_or_never
An extension trait for Futures that provides a variety of convenient adapters.
thanks, i think this should do it 🙂