Skip to content

Failed to call async function in custom middleware #1802

Answered by robjtede
SardineFish asked this question in Q&A
Discussion options

You must be logged in to vote

Since the returned future needs to be 'static, everything in the async move block needs to be owned/cloned. A common pattern to work around the lifetime issues is to use an Rc<RefCell<S>> in the service.

An example from the httpauth middleware: https://github.com/actix/actix-extras/blob/f970d908943126e505a5cb58a3af9aece7926e00/actix-web-httpauth/src/middleware.rs#L177.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@SardineFish
Comment options

Answer selected by SardineFish
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