Use Task::discard in websocket example

This commit is contained in:
Héctor Ramón Jiménez 2025-09-23 02:27:42 +02:00
parent 629e795784
commit 714c4982d6
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
2 changed files with 5 additions and 10 deletions

View file

@ -30,7 +30,6 @@ pub fn connect() -> impl Sipper<Never, Event> {
tokio::time::sleep(tokio::time::Duration::from_secs(1))
.await;
output.send(Event::Disconnected).await;
continue;
}
};

View file

@ -1,6 +1,5 @@
mod echo;
use iced::futures::stream;
use iced::widget::{
button, center, column, operation, row, scrollable, text, text_input,
};
@ -23,7 +22,6 @@ enum Message {
NewMessageChanged(String),
Send(echo::Message),
Echo(echo::Event),
Server,
}
impl WebSocket {
@ -34,7 +32,10 @@ impl WebSocket {
new_message: String::new(),
state: State::Disconnected,
},
operation::focus_next(),
Task::batch([
Task::future(echo::server::run()).discard(),
operation::focus_next(),
]),
)
}
@ -76,16 +77,11 @@ impl WebSocket {
operation::snap_to_end(MESSAGE_LOG)
}
},
Message::Server => Task::none(),
}
}
fn subscription(&self) -> Subscription<Message> {
Subscription::batch([
Subscription::run(|| stream::once(echo::server::run()))
.map(|_| Message::Server),
Subscription::run(echo::connect).map(Message::Echo),
])
Subscription::run(echo::connect).map(Message::Echo)
}
fn view(&self) -> Element<'_, Message> {