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

chore: Implement Sync for Consumer #291

Merged
merged 1 commit into from
Aug 11, 2023

Conversation

cirias
Copy link
Contributor

@cirias cirias commented Aug 11, 2023

Hi! This request adds the auto implementation of Sync for Consumer.

Currently, Sync is not implemented for Consumer, which causes error when trying to move the consumer to a backgound task. See the code below as an example.

async main() {
    let consumer: Consumer<TestData, _> = pulsar
        .consumer()
        .build()
        .await?;

    let mut app = App { consumer };

    tokio::task::spawn(app.run()).await.unwrap();
}

struct App {
    consumer: Consumer<TestData, TokioExecutor>,
}

impl App {
    async fn run(&mut self) {
        while let Some(_msg) = self.consumer.try_next().await.unwrap() {
            self.dosomething().await;
        }
    }

    async fn dosomething(&self) {}
}

  • Updated the example.

Copy link
Contributor

@tisonkun tisonkun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@tisonkun tisonkun merged commit b030ef9 into streamnative:master Aug 11, 2023
5 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.

2 participants