Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async use doesn't appear to work? #32

Open
rhomber opened this issue Jan 20, 2023 · 2 comments
Open

Async use doesn't appear to work? #32

rhomber opened this issue Jan 20, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@rhomber
Copy link

rhomber commented Jan 20, 2023

error[E0308]: mismatched types
  --> lit-attestation-service/src/handlers/attestation_intent.rs:34:9
   |
34 | /         Box::pin(async move {
35 | |             debug!(req = as_serde!(req); "AttestationIntentHandler");
36 | |
37 | |             // Create initial Attestation object.
...  |
77 | |             Ok(AttestationIntentResp { attestation, session_id })
78 | |         })
   | |__________^ one type is more general than the other
   |
   = note: expected struct `Box<dyn Any + std::marker::Send + Sync>`
              found struct `Box<dyn Any + std::marker::Send + Sync>`

error: higher-ranked lifetime error
  --> lit-attestation-service/src/handlers/attestation_intent.rs:34:9
   |
34 | /         Box::pin(async move {
35 | |             debug!(req = as_serde!(req); "AttestationIntentHandler");
36 | |
37 | |             // Create initial Attestation object.
...  |
77 | |             Ok(AttestationIntentResp { attestation, session_id })
78 | |         })
   | |__________^
   |
   = note: could not prove `Pin<Box<[async block@lit-attestation-service/src/handlers/attestation_intent.rs:34:18: 78:10]>>: CoerceUnsized<Pin<Box<(dyn futures::Future<Output = std::result::Result<AttestationIntentResp, lit_attestation::Error>> + std::marker::Send + 'b)>>>`

Which happens when i use async_trait or directly use BoxFuture. It all relates to this line:

CACHE.insert(session_id.clone(), Box::new(attestation.clone()), 1).await;

My cache is constructed:

pub static CACHE: Lazy<AsyncCache<String, Box<dyn Any + Send + Sync>>> =
    Lazy::new(|| AsyncCache::new(100, 10, tokio::spawn).expect("failed to create cache"));
@rhomber
Copy link
Author

rhomber commented Jan 20, 2023

Someone in the rust community (bruh![moment]) was able to get it working, if we create:

fn cache_session(session_id: String, attestation: Attestation) -> BoxFuture<'static, bool> {
    CACHE.insert(session_id, Box::new(attestation), 1).boxed()
}

and call that instead, it works!

So perhaps you need to provide a BoxFuture instead here?

@al8n
Copy link
Owner

al8n commented Jan 25, 2023

Thanks! I will look at it later.

@al8n al8n added the bug Something isn't working label Jan 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants