#done

5 messages · Page 1 of 1 (latest)

cedar ember
#

Generally you shouldn't need to manually use poll_* functions, you should use the async fn/Future-returning wrappers. In this case you probably want rs if let Ok(connection) = self.listener.accept().await { // ... } instead of self.listener.poll_accept

silent trout
#

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

cedar ember
# silent trout from what I understand .accept().await blocks the thread until a connection is r...

.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
silent trout
#

thanks, i think this should do it 🙂