Skip to content

Async use doesn't appear to work? #32

@rhomber

Description

@rhomber
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"));

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions