From 390106871788370dc084efa411f9a31df8a8e2ad Mon Sep 17 00:00:00 2001 From: Astro Date: Thu, 24 Mar 2022 03:26:30 +0100 Subject: [PATCH] tokio-xmpp: remove LocalSet from AsyncClient, making it Sync --- tokio-xmpp/src/client/async_client.rs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/tokio-xmpp/src/client/async_client.rs b/tokio-xmpp/src/client/async_client.rs index e2fdb102..bf6cd0e8 100644 --- a/tokio-xmpp/src/client/async_client.rs +++ b/tokio-xmpp/src/client/async_client.rs @@ -6,7 +6,6 @@ use std::str::FromStr; use std::task::Context; use tokio::net::TcpStream; use tokio::task::JoinHandle; -use tokio::task::LocalSet; #[cfg(feature = "tls-native")] use tokio_native_tls::TlsStream; #[cfg(feature = "tls-rust")] @@ -58,7 +57,7 @@ type XMPPStream = xmpp_stream::XMPPStream>; enum ClientState { Invalid, Disconnected, - Connecting(JoinHandle>, LocalSet), + Connecting(JoinHandle>), Connected(XMPPStream), } @@ -80,15 +79,14 @@ impl Client { /// Start a new client given that the JID is already parsed. pub fn new_with_config(config: Config) -> Self { - let local = LocalSet::new(); - let connect = local.spawn_local(Self::connect( + let connect = tokio::spawn(Self::connect( config.server.clone(), config.jid.clone(), config.password.clone(), )); let client = Client { config, - state: ClientState::Connecting(connect, local), + state: ClientState::Connecting(connect), reconnect: false, }; client @@ -196,18 +194,16 @@ impl Stream for Client { ClientState::Invalid => panic!("Invalid client state"), ClientState::Disconnected if self.reconnect => { // TODO: add timeout - let mut local = LocalSet::new(); - let connect = local.spawn_local(Self::connect( + let connect = tokio::spawn(Self::connect( self.config.server.clone(), self.config.jid.clone(), self.config.password.clone(), )); - let _ = Pin::new(&mut local).poll(cx); - self.state = ClientState::Connecting(connect, local); + self.state = ClientState::Connecting(connect); self.poll_next(cx) } ClientState::Disconnected => Poll::Ready(None), - ClientState::Connecting(mut connect, mut local) => { + ClientState::Connecting(mut connect) => { match Pin::new(&mut connect).poll(cx) { Poll::Ready(Ok(Ok(stream))) => { let bound_jid = stream.jid.clone(); @@ -226,9 +222,7 @@ impl Stream for Client { panic!("connect task: {}", e); } Poll::Pending => { - let _ = Pin::new(&mut local).poll(cx); - - self.state = ClientState::Connecting(connect, local); + self.state = ClientState::Connecting(connect); Poll::Pending } }