pub struct Watch<V: LiveValue> {
pub rx: tokio::sync::broadcast::Receiver<Update<V>>,
}
impl<V: LiveValue> Watch<V> {
/// Watch for changes to the subscribed value.
/// The provided closure will run whenever the value is updated.
///
/// To keep watching for changes, use `Control::Break` to close the
/// receiver.
pub fn on_update<F, Fut>(mut self, f: F)
where
F: Fn(Update<V>) -> Fut + Send + Sync + 'static,
Fut: Future<Output=Control> + Send + Sync + 'static
{
tokio::spawn(async move {
loop {
match self.rx.recv().await {
Ok(update) => {
if let Control::Break = (f)(update).await {
return;
}
},
Err(RecvError::Closed) => return,
_ => {}
}
}
});
}
}
error: async closure does not implement `Fn` because it captures state from its environment
--> src/lib.rs:829:23
|
829 | sub.on_update(async move |update| {
| --------- ^^^^^^^^^^^^^^^^^^^
| |
| required by a bound introduced by this call
|
note: required by a bound in `Watch::<V>::on_update`
--> src/lib.rs:757:12
|
755 | pub fn on_update<F, Fut>(mut self, f: F)
| --------- required by a bound in this associated function
756 | where
757 | F: Fn(Update<V>) -> Fut + Send + Sync + 'static,
| ^^^^^^^^^^^^^^^^^^^^ required by this bound in `Watch::<V>::on_update`
Hello! I am having trouble passing an async closure into a function that .awaits it in a loop. I understand it says it captures state in its environment, but I am cloning any captured values before moving them into the closure, so I'm not sure why I'm seeing that.
