Simplify subscription::channel example

This commit is contained in:
Héctor Ramón Jiménez 2024-07-02 19:01:04 +02:00
parent 4687bf7f14
commit 2b19471d1c
No known key found for this signature in database
GPG key ID: 7CC46565708259A7

View file

@ -369,30 +369,17 @@ where
/// // ...
/// }
///
/// enum State {
/// Starting,
/// Ready(mpsc::Receiver<Input>),
/// }
///
/// fn some_worker() -> Subscription<Event> {
/// struct SomeWorker;
///
/// subscription::channel(std::any::TypeId::of::<SomeWorker>(), 100, |mut output| async move {
/// let mut state = State::Starting;
///
/// loop {
/// match &mut state {
/// State::Starting => {
/// // Create channel
/// let (sender, receiver) = mpsc::channel(100);
/// let (sender, mut receiver) = mpsc::channel(100);
///
/// // Send the sender back to the application
/// output.send(Event::Ready(sender)).await;
///
/// // We are ready to receive messages
/// state = State::Ready(receiver);
/// }
/// State::Ready(receiver) => {
/// loop {
/// use iced_futures::futures::StreamExt;
///
/// // Read next input sent from `Application`
@ -408,8 +395,6 @@ where
/// }
/// }
/// }
/// }
/// }
/// })
/// }
/// ```