Skip to content

Commit

Permalink
Revert "Replace next_update with update_stream"
Browse files Browse the repository at this point in the history
This reverts commit b942670.
  • Loading branch information
Lonami committed Dec 21, 2024
1 parent 7d230d0 commit ac44ef8
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 158 deletions.
9 changes: 2 additions & 7 deletions lib/grammers-client/examples/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
use std::env;
use std::pin::pin;

use futures::{
future::{select, Either},
StreamExt,
};
use futures::future::{select, Either};
use simple_logger::SimpleLogger;
use tokio::{runtime, task};

Expand Down Expand Up @@ -74,8 +71,6 @@ async fn async_main() -> Result {
println!("Signed in!");
}

let mut update_stream = client.update_stream();

println!("Waiting for messages...");

// This code uses `select` on Ctrl+C to gracefully stop the client and have a chance to
Expand All @@ -87,7 +82,7 @@ async fn async_main() -> Result {
// so a manual `select` is used instead by pinning async blocks by hand.
loop {
let exit = pin!(async { tokio::signal::ctrl_c().await });
let upd = pin!(async { update_stream.select_next_some().await });
let upd = pin!(async { client.next_update().await });

let update = match select(exit, upd).await {
Either::Left(_) => break,
Expand Down
9 changes: 2 additions & 7 deletions lib/grammers-client/examples/inline-pagination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
use std::env;
use std::pin::pin;

use futures::{
future::{select, Either},
StreamExt,
};
use futures::future::{select, Either};
use simple_logger::SimpleLogger;
use tokio::{runtime, task};

Expand Down Expand Up @@ -137,12 +134,10 @@ async fn async_main() -> Result {
println!("Signed in!");
}

let mut update_stream = client.update_stream();

println!("Waiting for messages...");
loop {
let exit = pin!(async { tokio::signal::ctrl_c().await });
let upd = pin!(async { update_stream.select_next_some().await });
let upd = pin!(async { client.next_update().await });

let update = match select(exit, upd).await {
Either::Left(_) => {
Expand Down
22 changes: 9 additions & 13 deletions lib/grammers-client/examples/reconnection.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! this example demonstrate how to implement custom Reconnection Polies
use futures::TryStreamExt;
use grammers_client::session::Session;
use grammers_client::{Client, Config, InitParams, ReconnectionPolicy};
use std::ops::ControlFlow;
Expand Down Expand Up @@ -43,19 +42,16 @@ async fn async_main() -> Result {
/// happy listening to updates forever!!
use grammers_client::Update;

client
.update_stream()
.try_for_each_concurrent(None, |update| async {
match update {
Update::NewMessage(message) if !message.outgoing() => {
message.respond(message.text()).await.map(|_| ())
}
_ => Ok(()),
}
})
.await?;
loop {
let update = client.next_update().await?;

Ok(())
match update {
Update::NewMessage(message) if !message.outgoing() => {
message.respond(message.text()).await?;
}
_ => {}
}
}
}

fn main() -> Result {
Expand Down
Loading

0 comments on commit ac44ef8

Please sign in to comment.