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

Migrate to (std::)futures 0.3 and tokio 0.2 #31

Closed
ohmyarch opened this issue Aug 23, 2019 · 14 comments
Closed

Migrate to (std::)futures 0.3 and tokio 0.2 #31

ohmyarch opened this issue Aug 23, 2019 · 14 comments

Comments

@ohmyarch
Copy link

rust-lang/rust#63209 (comment)
https://tokio.rs/blog/2019-08-alphas/

@ohmyarch
Copy link
Author

@pimeys
Copy link

pimeys commented Sep 11, 2019

Could we also change the interface a bit to the direction of how r2d2 works, could it be possible now with std::future, async/await and Pin?

So we could be able to use it in a more synchronous-looking manner:

impl AsyncConnector for MyTestPostgresConnector {
    fn run(&self, query: String) -> FutureObj<'static, crate::Result<serde_json::Value>> {
	let fut = async move {
            let mut client = self.pool.get().await?;
            let stmt = client.prepare(query.as_str()).await?;
            let rows = client.query(&stmt, &[]).collect().await?;

            Ok(rows.into_json()?)
        };

        FutureObj::new(Box::new(fut))
    }
}

@githubaccount624
Copy link

githubaccount624 commented Sep 13, 2019

Any updates for this? In my app server grabbing the connection each request adds a lot of overhead. I'd like to use this with Rocket, but currently they're incompatible because async Rocket is already on std::future.

@khuey
Copy link
Collaborator

khuey commented Sep 13, 2019

Not really much we can do here until tokio-postgres at least supports these things, since we're heavily dependent on it.

@githubaccount624
Copy link

What is tokio-postgres still missing? I've been using its std-futures branch without any real issues for a couple weeks now.

@khuey
Copy link
Collaborator

khuey commented Sep 13, 2019

Maybe it's not missing anything in git, I haven't looked in a while. tokio-postgres doesn't really do releases unfortunately so it's hard to know when it's reached usable points.

@githubaccount624
Copy link

githubaccount624 commented Sep 13, 2019

Ah okay. Well I can give a bit of an endorsement here I think. I've been using the Rocket futures branch and the tokio-postgres futures branch in my project for the past month or so and haven't run into any issues yet.

I was talking to the Rocket developers just now and they're interested in using bb8 to implement an async connection pool for postgres in Rocket, but were just waiting on this crate to also update to std-futures. What do you think? :D

Unfortunately I have no idea what the effort required is to update from futures 0.1 to 0.3 since I'm still a Rust noob. Is it very hard?

@khuey
Copy link
Collaborator

khuey commented Sep 13, 2019

Alright, I'll take a look at where things stand but that's unlikely to happen before Sunday at the earliest.

I don't think futures 0.1->0.3 is going to be that painful.

@githubaccount624
Copy link

What! That's amazing news! Thanks so much!

@githubaccount624
Copy link

Hi @khuey I was wondering if you ever got a chance to check out tokio-postgres's futures branch and if it could work with bb8.

@djc
Copy link
Owner

djc commented Oct 12, 2019

I've got an initial attempt in #37 that's most of the way there.

@ohmyarch
Copy link
Author

tokio-postgres v0.5.0-alpha.1 which uses std::futures::Future and async/await syntax is out.

@ohmyarch
Copy link
Author

ohmyarch commented Nov 8, 2019

async/await syntax stabilized in 1.39.

@djc
Copy link
Owner

djc commented Dec 31, 2019

This is done.

@djc djc closed this as completed Dec 31, 2019
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

No branches or pull requests

5 participants