diff --git a/crates/teloxide/src/update_listeners.rs b/crates/teloxide/src/update_listeners.rs index 66ca97d4..de2c4228 100644 --- a/crates/teloxide/src/update_listeners.rs +++ b/crates/teloxide/src/update_listeners.rs @@ -44,6 +44,8 @@ mod polling; #[allow(deprecated)] pub use self::polling::{polling, polling_default, Polling, PollingBuilder, PollingStream}; +type BoxFut<'a, T> = Pin + Send + 'a>>; + /// An update listener. /// /// Implementors of this trait allow getting updates from Telegram. See @@ -73,9 +75,7 @@ pub trait UpdateListener { /// should call `set_webhook`. /// /// [`Stream`]: AsUpdateStream::Stream - fn listen( - &mut self, - ) -> Pin, Self::SetupErr>> + Send + '_>>; + fn listen(&mut self) -> BoxFut<'_, Result, Self::SetupErr>>; /// Hint which updates should the listener listen for. /// diff --git a/crates/teloxide/src/update_listeners/polling.rs b/crates/teloxide/src/update_listeners/polling.rs index 2cea9bd1..8686fe5e 100644 --- a/crates/teloxide/src/update_listeners/polling.rs +++ b/crates/teloxide/src/update_listeners/polling.rs @@ -447,9 +447,9 @@ fn polling_is_send() { assert_send(&polling.listen()); assert_send(&polling.stop_token()); - _ = async { + drop(async { assert_send(&polling.listen().await.unwrap()); - }; + }); fn assert_send(_: &impl Send) {} }