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

Add async_std support #281

Merged
merged 22 commits into from
Mar 3, 2020
Merged

Add async_std support #281

merged 22 commits into from
Mar 3, 2020

Conversation

DavidBM
Copy link
Contributor

@DavidBM DavidBM commented Feb 5, 2020

Based in the conversation here: #280

This branch comes from https://github.com/Marwes/redis-rs/tree/combine-4 If you merge this branch you will be merging this pull request too: #272

When I needed to duplicate the method and it was public, I tried to create two variants (one with _tokio suffix and the other with _async_std) and leave the original method calling the _tokio variant. Still, very provably this mean breaking changes.

All test pass in my pc (Pop_os 19.10)

Let me know if I need to change anything!

@DavidBM DavidBM changed the title Add support for . Add async_std support Feb 5, 2020
@DavidBM DavidBM requested a review from Marwes February 5, 2020 14:07
@DavidBM
Copy link
Contributor Author

DavidBM commented Feb 5, 2020

Fixing windows build

Copy link
Collaborator

@Marwes Marwes left a comment

Choose a reason for hiding this comment

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

Cargo.toml Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
src/client.rs Outdated Show resolved Hide resolved
src/client.rs Outdated Show resolved Hide resolved
src/aio.rs Outdated Show resolved Hide resolved
src/aio.rs Outdated Show resolved Hide resolved
@@ -0,0 +1,310 @@
use redis;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would be nice to not duplicate the tests here, not critical to fix however.

(Maybe an environment variable could switch which method call the support module uses?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, we can flag them. I duplicated them as a fast way to test everything with async_std. I think we can add an argument for that

Copy link
Collaborator

Choose a reason for hiding this comment

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

For now this also acts as an example for async-std.
When we refactor common parts out we should add a minimal example (just as the await-async one) for async-std usage

src/aio.rs Outdated Show resolved Hide resolved
@DavidBM
Copy link
Contributor Author

DavidBM commented Feb 5, 2020

ok. I'm looking into the suggestions. I don't know if I will have time today, if not, I hope I can do it tomorrow.

@mitsuhiko
Copy link
Contributor

I have to say that having methods end in _tokio etc. is a pretty awful experience. I wonder if we can hide this behind some traits at least. It's quite frustrating that we need to do this at all to be honest.

@DavidBM
Copy link
Contributor Author

DavidBM commented Feb 5, 2020

We discussed about that in #280 and didn't find a way to do it. I don't know how to make Rust to choose the correct implementation depending of the reactor. I agree that it would be much better to hide it.

@Marwes
Copy link
Collaborator

Marwes commented Feb 5, 2020

We could actually do something like this.

#[cfg(any(feature = "tokio", feature = "async-std")]
fn get_async_connection(&self) -> RedisResult<Connection> {
    #[cfg(all(feature = "tokio", not(feature = "async-std"))]
    {
        // Call tokio connect
    }

    #[cfg(all(not(feature = "tokio"), feature = "async-std")]
    {
        // Call async-std connect
    }

    #[cfg(all(feature = "tokio", feature = "async-std")]
    {
        if tokio::runtime::Handle::try_current().is_ok() {
            // Call tokio connect
        } else {
            // Call async-std connect
        }
    }
}

Complicates internally but simplifies for users.

@DavidBM
Copy link
Contributor Author

DavidBM commented Feb 5, 2020

Hi!

I think I made all the changes proposed.

I may say that with the features flag and the cfg attributes, the function MultiplexedConnection::create_connection is getting very long. Adding a third executor would make that function very very long.

About the proposed method, I think it may work. I will try.

@DavidBM
Copy link
Contributor Author

DavidBM commented Feb 5, 2020

I tried to add something like what you proposed @Marwes

I'm not making tokio an optional feature because the function MultiplexedConnection::create_connection is getting very very long and making Tokio optional would make it too much.

I named the feature for async_std "async-std-aio" because seems tat features and dependencies names cannot collide.

@DavidBM
Copy link
Contributor Author

DavidBM commented Feb 5, 2020

Going to sleep, let me know tomorrow your thoughts!

@Marwes
Copy link
Collaborator

Marwes commented Feb 6, 2020

I named the feature for async_std "async-std-aio" because seems tat features and dependencies names cannot collide.

As a workaround you can rename the package and then add your own async-std feature.

async-std-dep = { version = "*", package = "async-std" }

@DavidBM
Copy link
Contributor Author

DavidBM commented Feb 7, 2020

Done!

@DavidBM
Copy link
Contributor Author

DavidBM commented Feb 10, 2020

@mitsuhiko @Marwes Are you happy with this PR?

If yes, I'm planning some changes on my library, when do you think (more or less) that you will be able to merge this PR?

@DavidBM DavidBM requested a review from Marwes February 13, 2020 13:44
@Marwes
Copy link
Collaborator

Marwes commented Feb 13, 2020

@DavidBM Did you see DavidBM#1 ? LGTM, modulo formatting failing on CI which should be fixed.

It is based on #280 which I am also fine with, but ideally someone else should be fine with that PR as well :)

@DavidBM
Copy link
Contributor Author

DavidBM commented Feb 13, 2020

Nice! That makes a lot of sense!

I didn't see it. I will make tokio optional and then request the review again. Thanks!

@DavidBM
Copy link
Contributor Author

DavidBM commented Feb 13, 2020

At the end I found a better way (in my opinion) for naming the features.

Tokio and Async_std are optional. If aio is enabled without them, there is a compilation error. In any case, I don't think that anyone runs in that problem. The code should be ready for adding new reactors in the future.

Later I will check the errors in the builds and fix them.

@DavidBM
Copy link
Contributor Author

DavidBM commented Feb 13, 2020

Ok, all test pass. Pull request ready to go.

@badboy badboy self-requested a review February 16, 2020 22:16
@badboy
Copy link
Collaborator

badboy commented Feb 20, 2020

I merged #272, so if you rebase this it would make the review easier (unfortunately GitHub is awful in simply hiding or separating these commits easily).
If you're at it squashing those "fix" commits into their appropriate parent commits would help keep changes per commit reviewable.

(Don't worry if that is too much work, we can get through this somehow, and of course already thank you for investing the time!)

Copy link
Collaborator

@badboy badboy left a comment

Choose a reason for hiding this comment

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

I agree with @mitsuhiko that exposing _tokio and _async_std methods is indeed suboptimal, but I don't see a way around it either.
We could of course make the features mutual-exclusive, but due to how cargo features work that might lead to an even worse experience for users. Hmmm, I don't have a solution here.

I think the code here is ok, see some inline nits though.

Cargo.toml Outdated Show resolved Hide resolved
src/aio.rs Outdated Show resolved Hide resolved
src/aio.rs Outdated Show resolved Hide resolved
src/aio.rs Outdated Show resolved Hide resolved
src/aio.rs Outdated Show resolved Hide resolved
src/aio.rs Outdated Show resolved Hide resolved
src/aio.rs Outdated Show resolved Hide resolved
src/aio.rs Outdated Show resolved Hide resolved
@@ -0,0 +1,310 @@
use redis;
Copy link
Collaborator

Choose a reason for hiding this comment

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

For now this also acts as an example for async-std.
When we refactor common parts out we should add a minimal example (just as the await-async one) for async-std usage

src/aio.rs Outdated Show resolved Hide resolved
src/aio.rs Outdated Show resolved Hide resolved
DavidBM and others added 11 commits February 22, 2020 18:42
Reduce branching in create_connection
- replaces the "aio" default feature by the "tokio-comp" feature.
- async-std-comp and tokio-comp features automatically activate aio feature
- enabling aio without tokio-comp or async-std-comp will result in a compilation error
fix feature flags names

fix windows test

format code

enable async_std and tokio support by default
Code review
@DavidBM
Copy link
Contributor Author

DavidBM commented Feb 22, 2020

Hi! I made the requested changes. I see that github is showing many commits, still, the diff more clear now. Let me know if anything else is needed! And thanks for taking the time to do a code review!

Copy link
Collaborator

@badboy badboy left a comment

Choose a reason for hiding this comment

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

With the one question left I think this is ready to be merged.
I'll give it a final look tomorrow then and we can land this (and maybe even cut a release)

src/aio.rs Outdated Show resolved Hide resolved
@DavidBM
Copy link
Contributor Author

DavidBM commented Feb 23, 2020

Done! :)

@DavidBM
Copy link
Contributor Author

DavidBM commented Mar 1, 2020

I fixed an error caused by a new code that was not adapted to the async_std and tokio.

@Marwes
Copy link
Collaborator

Marwes commented Mar 2, 2020

Looks like a formatting error still, looks good otherwise.

@DavidBM
Copy link
Contributor Author

DavidBM commented Mar 2, 2020

Ohh, sorry. I fixed and left it running without checking it. Should be fixed now.

@badboy
Copy link
Collaborator

badboy commented Mar 2, 2020

Woops. Managed to not land it last week. I promise to get to it today.

@badboy badboy merged commit cc9863b into redis-rs:master Mar 3, 2020
@badboy
Copy link
Collaborator

badboy commented Mar 3, 2020

Thank you so much!

@DavidBM
Copy link
Contributor Author

DavidBM commented Mar 3, 2020

Thanks to you all! I have learned a lot during the process!

barshaul pushed a commit to barshaul/redis-rs that referenced this pull request Jul 11, 2024
Increase timeout for cluster creation.
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.

4 participants