// Copyright 2023 System76 // SPDX-License-Identifier: MPL-2.0 //! 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. pub fn batch, Y: Send + 'static>( tasks: impl IntoIterator>, ) -> iced::Task { iced::Task::batch(tasks).map(Into::into) } /// Yields a task which will run the future on the runtime executor. pub fn future, Y: 'static>( future: impl Future + Send + 'static, ) -> iced::Task { iced::Task::future(async move { future.await.into() }) } /// Yields a task which will return a message. pub fn message, Y: 'static>(message: X) -> iced::Task { future(async move { message.into() }) } /// Yields a task which will run a stream on the runtime executor. pub fn stream + 'static, Y: 'static>( stream: impl Stream + Send + 'static, ) -> iced::Task { iced::Task::stream(stream.map(Into::into)) } pub fn none() -> iced::Task { iced::Task::none() }