iced/beacon/src/stream.rs
Héctor Ramón Jiménez f618382a0d
Run cargo fmt
2025-03-04 19:12:31 +01:00

15 lines
372 B
Rust

use futures::Future;
use futures::channel::mpsc;
use futures::stream::{self, Stream, StreamExt};
pub fn channel<T, F>(f: impl Fn(mpsc::Sender<T>) -> F) -> impl Stream<Item = T>
where
F: Future<Output = ()>,
{
let (sender, receiver) = mpsc::channel(1);
stream::select(
receiver,
stream::once(f(sender)).filter_map(|_| async { None }),
)
}