Skip to content

How to implement __aiter__ ? #5261

Discussion options

You must be logged in to vote

I don't know if you want to achieve that or not but I think that's the example

use std::pin::Pin;
use std::sync::Arc;

use futures::Stream;
use futures::stream::StreamExt;
use pyo3::exceptions::PyStopAsyncIteration;
use pyo3::prelude::*;
use pyo3_async_runtimes::tokio::future_into_py;
use tokio::sync::RwLock;

#[pyclass]
#[derive(Clone)]
pub struct Events {
    inner: Arc<RwLock<Pin<Box<dyn Stream<Item = PyObject> + Send + Sync + Unpin>>>>,
}

#[pymethods]
impl Events {
    #[new]
    pub fn new(py:Python, events:Vec<Py<PyAny>>) -> PyResult<Self> {

        let py_iter = events.iter();
        let mut items = vec![];

        for item in py_iter {
            items.push(item.into_pyobject(py

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@JadKHaddad
Comment options

@AriBermeki
Comment options

@JadKHaddad
Comment options

@AriBermeki
Comment options

Answer selected by JadKHaddad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants