mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-23 06:51:01 +01:00
Make StatefulListener::new
a little more convinient
Remove `timeout_hint` from the `StatefulListener::new` function. This parameter is confusing and is likely to be set to `None` in most cases. Add a `StatefulListener::new_with_timeout_hint` parameter which is the same as the old `StatefulListener::new`.
This commit is contained in:
parent
76dee997e0
commit
c378d6ef4e
3 changed files with 15 additions and 3 deletions
|
@ -62,7 +62,7 @@ pub async fn webhook(bot: AutoSend<Bot>) -> impl update_listeners::UpdateListene
|
|||
|
||||
fn streamf<S, T>(state: &mut (S, T)) -> &mut S { &mut state.0 }
|
||||
|
||||
StatefulListener::new((stream, stop_token), streamf, |state: &mut (_, AsyncStopToken)| state.1.clone(), None::<for<'a> fn(&'a _) -> _>)
|
||||
StatefulListener::new((stream, stop_token), streamf, |state: &mut (_, AsyncStopToken)| state.1.clone())
|
||||
}
|
||||
|
||||
async fn run() {
|
||||
|
|
|
@ -54,7 +54,7 @@ pub async fn webhook(bot: AutoSend<Bot>) -> impl update_listeners::UpdateListene
|
|||
|
||||
fn streamf<S, T>(state: &mut (S, T)) -> &mut S { &mut state.0 }
|
||||
|
||||
StatefulListener::new((stream, stop_token), streamf, |state: &mut (_, AsyncStopToken)| state.1.clone(), None::<for<'a> fn(&'a _) -> _>)
|
||||
StatefulListener::new((stream, stop_token), streamf, |state: &mut (_, AsyncStopToken)| state.1.clone())
|
||||
}
|
||||
|
||||
async fn run() {
|
||||
|
|
|
@ -39,9 +39,21 @@ pub struct StatefulListener<St, Assf, Sf, Thf> {
|
|||
pub timeout_hint: Option<Thf>,
|
||||
}
|
||||
|
||||
impl<St, Assf, Sf> StatefulListener<St, Assf, Sf, for<'a> fn(&'a St) -> Option<Duration>> {
|
||||
/// Creates new stateful listener from it's components.
|
||||
pub fn new(state: St, stream: Assf, stop_token: Sf) -> Self {
|
||||
Self { state, stream, stop_token, timeout_hint: None }
|
||||
}
|
||||
}
|
||||
|
||||
impl<St, Assf, Sf, Thf> StatefulListener<St, Assf, Sf, Thf> {
|
||||
/// Creates new stateful listener from it's components.
|
||||
pub fn new(state: St, stream: Assf, stop_token: Sf, timeout_hint: Option<Thf>) -> Self {
|
||||
pub fn new_with_timeout_hint(
|
||||
state: St,
|
||||
stream: Assf,
|
||||
stop_token: Sf,
|
||||
timeout_hint: Option<Thf>,
|
||||
) -> Self {
|
||||
Self { state, stream, stop_token, timeout_hint }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue