feat(task): add stream function
This commit is contained in:
parent
cb6ea4c7c3
commit
77c3a8ed90
2 changed files with 9 additions and 0 deletions
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
//! Create asynchronous actions to be performed in the background.
|
||||
|
||||
use futures::stream::{Stream, StreamExt};
|
||||
use std::future::Future;
|
||||
|
||||
/// Yields a task which contains a batch of tasks.
|
||||
|
|
@ -23,3 +24,10 @@ pub fn future<X: Into<Y>, Y: 'static>(
|
|||
pub fn message<X: Send + 'static + Into<Y>, Y: 'static>(message: X) -> iced::Task<Y> {
|
||||
future(async move { message.into() })
|
||||
}
|
||||
|
||||
/// Yields a task which will run a stream on the runtime executor.
|
||||
pub fn stream<X: Into<Y> + 'static, Y: 'static>(
|
||||
stream: impl Stream<Item = X> + Send + 'static,
|
||||
) -> iced::Task<Y> {
|
||||
iced::Task::stream(stream.map(Into::into))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue