Simplify subscription::channel example
This commit is contained in:
parent
4687bf7f14
commit
2b19471d1c
1 changed files with 14 additions and 29 deletions
|
|
@ -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
|
|||
/// }
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
/// })
|
||||
/// }
|
||||
/// ```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue