diff options
| author | 2024-07-02 19:01:04 +0200 | |
|---|---|---|
| committer | 2024-07-02 19:01:40 +0200 | |
| commit | 2b19471d1cfe4cf034b026aa6620b1685a5ab772 (patch) | |
| tree | 91f1cf78a7ecf960d3e9ef74ac84a3be319f2308 /futures | |
| parent | 4687bf7f146792c6136987d79aa16aa9a7c5db81 (diff) | |
| download | iced-2b19471d1cfe4cf034b026aa6620b1685a5ab772.tar.gz iced-2b19471d1cfe4cf034b026aa6620b1685a5ab772.tar.bz2 iced-2b19471d1cfe4cf034b026aa6620b1685a5ab772.zip | |
Simplify `subscription::channel` example
Diffstat (limited to '')
| -rw-r--r-- | futures/src/subscription.rs | 43 | 
1 files changed, 14 insertions, 29 deletions
| diff --git a/futures/src/subscription.rs b/futures/src/subscription.rs index 316fc44d..5ec39582 100644 --- a/futures/src/subscription.rs +++ b/futures/src/subscription.rs @@ -369,44 +369,29 @@ 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); +///         // Create channel +///         let (sender, mut receiver) = mpsc::channel(100);  /// -///                     // Send the sender back to the application -///                     output.send(Event::Ready(sender)).await; +///         // 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) => { -///                     use iced_futures::futures::StreamExt; +///         loop { +///             use iced_futures::futures::StreamExt;  /// -///                     // Read next input sent from `Application` -///                     let input = receiver.select_next_some().await; +///             // Read next input sent from `Application` +///             let input = receiver.select_next_some().await;  /// -///                     match input { -///                         Input::DoSomeWork => { -///                             // Do some async work... +///             match input { +///                 Input::DoSomeWork => { +///                     // Do some async work...  /// -///                             // Finally, we can optionally produce a message to tell the -///                             // `Application` the work is done -///                             output.send(Event::WorkFinished).await; -///                         } -///                     } +///                     // Finally, we can optionally produce a message to tell the +///                     // `Application` the work is done +///                     output.send(Event::WorkFinished).await;  ///                 }  ///             }  ///         } | 
