Fix polling's StopToken not being Send

This commit is contained in:
Maybe Waffle 2022-01-18 19:27:57 +03:00
parent 818a493a4a
commit a7182962f7
3 changed files with 16 additions and 3 deletions

View file

@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Infinite retries while stopping polling listener ([issue 496](https://github.com/teloxide/teloxide/issues/496))
- `polling{,_default}` and it's `Stream` and `StopToken` not being `Send` (and by extension fix the same problem with `repl`s)
## 0.5.3 - 2021-10-25

View file

@ -83,3 +83,12 @@ pub async fn repl_with_listener<'a, R, H, Fut, E, L, ListenerE>(
)
.await;
}
#[test]
fn repl_is_send() {
let bot = crate::Bot::new("");
let repl = crate::repl(bot, |_| async { crate::respond(()) });
assert_send(&repl);
fn assert_send(_: &impl Send) {}
}

View file

@ -7,7 +7,7 @@ use futures::{
use crate::{
dispatching::{
stop_token::{AsyncStopFlag, AsyncStopToken},
stop_token::{AsyncStopFlag, AsyncStopToken, StopToken},
update_listeners::{stateful_listener::StatefulListener, UpdateListener},
},
payloads::{GetUpdates, GetUpdatesSetters as _},
@ -22,7 +22,9 @@ use crate::{
/// ## Notes
///
/// This function will automatically delete a webhook if it was set up.
pub async fn polling_default<R>(requester: R) -> impl UpdateListener<R::Err>
pub async fn polling_default<R>(
requester: R,
) -> impl UpdateListener<R::Err, StopToken = impl Send + StopToken>
where
R: Requester + Send + 'static,
<R as Requester>::GetUpdates: Send,
@ -48,7 +50,7 @@ pub fn polling<R>(
timeout: Option<Duration>,
limit: Option<u8>,
allowed_updates: Option<Vec<AllowedUpdate>>,
) -> impl UpdateListener<R::Err>
) -> impl UpdateListener<R::Err, StopToken = impl Send + StopToken>
where
R: Requester + Send + 'static,
<R as Requester>::GetUpdates: Send,
@ -172,6 +174,7 @@ fn polling_is_send() {
assert_send(&polling);
assert_send(&polling.as_stream());
assert_send(&polling.stop_token());
fn assert_send(_: &impl Send) {}
}