I’ve got an iced app whose update
function looks roughly like this:
struct UI {
pub fn update(&mut self, message: Message) -> Task<Message> {
let task_a = function_a(message);
let task_b = function_b(message);
let task_c = match message {
Message::Foo => {
// do something
Task::done(Message::Bar)
}
Message::Baz => {
// do something else
Task::none()
}
}
// Chain the tasks together and return
The problem comes with chaining the tasks. From the source for version 0.13.2, the chain
method looks like this:
/// Chains a new [`Task`] to be performed once the current one finishes completely.
pub fn chain(self, task: Self) -> Self
where
T: 'static,
{
match self.0 {
None => task,
Some(first) => match task.0 {
None => Task::none(),
Some(second) => Task(Some(boxed_stream(first.chain(second)))),
},
}
}
which, if I’m reading this right, means that having Task::none().chain(Task::done(Message::Foo))
will return Task::done(Message::Foo)
, which makes sense, but Task::done(Message::Foo).chain(Task::none)
will just return Task::none()
, which is what I’m seeing.
What I need is a way to aggregate a set of tasks in such a way as to run the non-none()
tasks in sequence, but skip over the Task::none()
s in the set.
FWIW, I did try just returning Option<Task<Message>>
from my functions, and then putting the tasks in a Vec, and then flattening the vec and turning it into a Stream
to pass into Task::stream
, but, since Tasks aren’t cloneable, I couldn’t find a way to get the Tasks out of the vec and into the stream.
Any help would be greatly appreciated!!
-Jack