refactor!: improve surface action handling and adjust libcosmic API

This commit is contained in:
Michael Aaron Murphy 2025-03-05 16:01:23 +01:00 • committed by Ashley Wulber
parent 2c10e4362a
commit adb08f9daf
No known key found for this signature in database
GPG key ID: 5216D4F46A90A820
23 changed files with 755 additions and 799 deletions

25
src/task.rs Normal file
View file

@ -0,0 +1,25 @@
// Copyright 2023 System76 <info@system76.com>
// SPDX-License-Identifier: MPL-2.0
//! Create asynchronous actions to be performed in the background.
use std::future::Future;
/// Yields a task which contains a batch of tasks.
pub fn batch<X: Send + 'static + Into<Y>, Y: Send + 'static>(
tasks: impl IntoIterator<Item = iced::Task<X>>,
) -> iced::Task<Y> {
iced::Task::batch(tasks).map(Into::into)
}
/// Yields a task which will run the future on the runtime executor.
pub fn future<X: Into<Y>, Y: 'static>(
future: impl Future<Output = X> + Send + 'static,
) -> iced::Task<Y> {
iced::Task::future(async move { future.await.into() })
}
/// Yields a task which will return a message.
pub fn message<X: Send + 'static + Into<Y>, Y: 'static>(message: X) -> iced::Task<Y> {
future(async move { message.into() })
}