Any idea how can I achieve something like the following?
The compiler complains that tx
doesn't live long enough, and rightly so. How can I return a future that captures the variables it needs?
use std::future::Future;
async fn register_callback<F>(f :impl Fn() -> F)
where
F: Future + Send + 'static
{
f().await;
}
#[tokio::main]
async fn main() {
let (tx, _) = tokio::sync::mpsc::channel::<()>(1);
register_callback(|| {
tx.clone().send(())
});
}