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

class method support with async #2388

Closed
b23r0 opened this issue May 18, 2022 · 4 comments
Closed

class method support with async #2388

b23r0 opened this issue May 18, 2022 · 4 comments

Comments

@b23r0
Copy link

b23r0 commented May 18, 2022

I think it's very necessary to support asynchrony for class methods, in the form of something like this.

#[pymethods]
impl Test{

    #[new]
    pub fn new() -> PyResult<Test> {
        Ok(Test{})
    }

    // now report `async fn` is not yet supported for Python functions.
    async pub fn async_test(&mut self) -> PyResult<()> {
        Ok(())
    }
}
@mejrs
Copy link
Member

mejrs commented May 18, 2022

You can use the pyo3-asyncio crate for this. You have to make a normal method that returns a future object, similar to the examples at https://docs.rs/pyo3-asyncio/latest/pyo3_asyncio/index.html

@b23r0
Copy link
Author

b23r0 commented May 19, 2022

You can use the pyo3-asyncio crate for this. You have to make a normal method that returns a future object, similar to the examples at https://docs.rs/pyo3-asyncio/latest/pyo3_asyncio/index.html

I know that normal functions can implement async, but I hope class methods can too.

@davidhewitt
Copy link
Member

My understanding was that you can use pyo3-asyncio to implement #[pymethods] too.

@davidhewitt
Copy link
Member

I'm also going to close this, as a duplicate of #1632.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants