-
Notifications
You must be signed in to change notification settings - Fork 566
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
Conversation
Fixing windows build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Diff without most of the changes in #272 https://github.com/mitsuhiko/redis-rs/pull/281/files/a69d03bcf17592f48f3cc10fe4a694f1800c3946..b3163c1aeb92d88f7cbf2565a1a9d54a7ff9f042
@@ -0,0 +1,310 @@ | |||
use redis; |
There was a problem hiding this comment.
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?)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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. |
I have to say that having methods end in |
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. |
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. |
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. |
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. |
Going to sleep, let me know tomorrow your thoughts! |
As a workaround you can rename the package and then add your own
|
Done! |
@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? |
Nice! That makes a lot of sense! I didn't see it. I will make tokio optional and then request the review again. Thanks! |
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. |
Ok, all test pass. Pull request ready to go. |
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). (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!) |
There was a problem hiding this 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.
@@ -0,0 +1,310 @@ | |||
use redis; |
There was a problem hiding this comment.
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
before rebase
fix windows build fix missing config attributes for aio
fix tests
fix windows build
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
sync with master
Code review
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! |
There was a problem hiding this 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)
Done! :) |
I fixed an error caused by a new code that was not adapted to the async_std and tokio. |
Looks like a formatting error still, looks good otherwise. |
Ohh, sorry. I fixed and left it running without checking it. Should be fixed now. |
Woops. Managed to not land it last week. I promise to get to it today. |
Thank you so much! |
Thanks to you all! I have learned a lot during the process! |
Increase timeout for cluster creation.
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!