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

fix: correctly support !Send Actix APIs in server functions #3326

Merged
merged 2 commits into from
Dec 7, 2024

Conversation

gbj
Copy link
Collaborator

@gbj gbj commented Dec 6, 2024

Actix pins requests and responses to a single thread, allowing it to use a number of !Send types in its ecosystem. You need to be able to hold these across .await points.

Leptos server functions and resources want server functions to be Send.

The #[server] macro currently includes a workaround for Actix that automatically wraps a server fn body in SendWrapper in the trait implementation. However, it didn't do this in the dummy function body, with the result that this didn't actually work—it would work in the trait implementation but not the dummy function. (The dummy function only needs to exist for better rust-analyzer support.)

Test case:

#[server]
pub async fn list_post_metadata() -> Result<Vec<PostMetadata>, ServerFnError> {
    // really these would be some Actix ecosystem type that's an Rc internally
    let unsend = std::rc::Rc::new(());
    tokio::time::sleep(std::time::Duration::from_secs(1)).await;
    let _unsend = unsend.clone();
    Ok(POSTS
        .iter()
        .map(|data| PostMetadata {
            id: data.id,
            title: data.title.clone(),
        })
        .collect())
}

@gbj gbj merged commit 2aa9827 into main Dec 7, 2024
74 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant