summaryrefslogtreecommitdiffstats
path: root/runtime/src/task.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector@hecrj.dev>2024-06-20 01:23:01 +0200
committerLibravatar GitHub <noreply@github.com>2024-06-20 01:23:01 +0200
commit714d4503154a6224c26f2eed6e399c73d57b4bf8 (patch)
tree9456eb2d40f2761c29dfa51f370efe11dc22f5e5 /runtime/src/task.rs
parent19db068bbbebcda1756720525da247f35bd3a5e0 (diff)
parentc5f4bebeda8d6ef10efade7933a5ee58f06b62d1 (diff)
downloadiced-714d4503154a6224c26f2eed6e399c73d57b4bf8.tar.gz
iced-714d4503154a6224c26f2eed6e399c73d57b4bf8.tar.bz2
iced-714d4503154a6224c26f2eed6e399c73d57b4bf8.zip
Merge pull request #2469 from iced-rs/unify-shell-runtimes
`Daemon` API and Shell Runtime Unification
Diffstat (limited to 'runtime/src/task.rs')
-rw-r--r--runtime/src/task.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/runtime/src/task.rs b/runtime/src/task.rs
index 740360ac..b8a83d6d 100644
--- a/runtime/src/task.rs
+++ b/runtime/src/task.rs
@@ -242,6 +242,39 @@ impl<T> Task<T> {
}
}
+impl<T> Task<Option<T>> {
+ /// Executes a new [`Task`] after this one, only when it produces `Some` value.
+ ///
+ /// The value is provided to the closure to create the subsequent [`Task`].
+ pub fn and_then<A>(
+ self,
+ f: impl Fn(T) -> Task<A> + MaybeSend + 'static,
+ ) -> Task<A>
+ where
+ T: MaybeSend + 'static,
+ A: MaybeSend + 'static,
+ {
+ self.then(move |option| option.map_or_else(Task::none, &f))
+ }
+}
+
+impl<T, E> Task<Result<T, E>> {
+ /// Executes a new [`Task`] after this one, only when it succeeds with an `Ok` value.
+ ///
+ /// The success value is provided to the closure to create the subsequent [`Task`].
+ pub fn and_then<A>(
+ self,
+ f: impl Fn(T) -> Task<A> + MaybeSend + 'static,
+ ) -> Task<A>
+ where
+ T: MaybeSend + 'static,
+ E: MaybeSend + 'static,
+ A: MaybeSend + 'static,
+ {
+ self.then(move |option| option.map_or_else(|_| Task::none(), &f))
+ }
+}
+
impl<T> From<()> for Task<T>
where
T: MaybeSend + 'static,