Skip to content

I can't seem to use Actions at all without running into lifetime issues #2126

Answered by gbj
J-Cake asked this question in Q&A
Discussion options

You must be logged in to vote

The async closure feature maybe giving you a less-than-helpful helpful error here. Yours is the equivalent of this

move |upload: &Upload| async move {
  upload.dispatch().await
}

So you can see the &Upload reference is moved into the async block. This means that the async block has some lifetime &'a, which is the lifetime of &'a Upload.

But the function signature is this

pub fn new<F, Fu>(action_fn: F) -> Self
where
    F: Fn(&I) -> Fu + 'static,
    Fu: Future<Output = O> + 'static,

i.e., Fu the Future needs to be 'static: it cannot hold references to anything outside itself, but needs to own its own data. Ultimately this is a hard requirement of handing the Future off to wasm-bindgen-fu…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@J-Cake
Comment options

Answer selected by J-Cake
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants