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
*: switch to futures 0.3 #447
Conversation
Signed-off-by: Jay Lee <BusyJayLee@gmail.com>
src/call/mod.rs
Outdated
} | ||
} | ||
) -> Result<()> { | ||
// `start_send` is sopposed to be called after `poll_ready` returns ready. |
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.
Typo: sopposed
-> supposed
Signed-off-by: Jay Lee <BusyJayLee@gmail.com>
Signed-off-by: Jay Lee <BusyJayLee@gmail.com>
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.
Nice! This is really cool, I love how much better it makes the examples look. I have some comments inline, but most are small and the PR mostly lgtm.
interop/src/bin/client.rs
Outdated
use crate::grpc::{ChannelBuilder, ChannelCredentialsBuilder, Environment}; | ||
use crate::grpc_proto::util; | ||
use clap::{App, Arg}; | ||
use futures::executor::block_on; |
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.
style nit: it is better to import the module and qualify the function with the module name, e.g., import futures::executor
and use executor::block_on
.
@@ -64,5 +64,5 @@ fn main() { | |||
} | |||
server.start(); | |||
|
|||
let _ = future::empty::<(), ()>().wait(); | |||
block_on(futures::future::pending::<()>()); |
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.
Same thing here with tokio::main
@@ -35,8 +34,7 @@ impl Client { | |||
req: &Req, | |||
opt: CallOption, | |||
) -> Result<Resp> { | |||
let f = self.unary_call_async(method, req, opt)?; | |||
f.wait() | |||
block_on(self.unary_call_async(method, req, opt)?) |
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.
Ideally, we wouldn't expose API that uses block_on
since it means the caller can't use the function if they are using their own executor. Ideally we would only provide the async API unless the unary_call
can be implemented without using async IO, the caller then only needs to use block_on
. If we want to keep this function for back compat, then could you add to the doc comment that this function uses the default executor from the futures crate.
src/server.rs
Outdated
@@ -569,7 +569,7 @@ impl Drop for Server { | |||
// TODO: don't wait here | |||
let f = self.shutdown(); | |||
self.cancel_all_calls(); | |||
let _ = f.wait(); | |||
let _ = futures::executor::block_on(f); |
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.
This is not ideal since it forces the user to use the default executor. Until we get async destructors, I think the best thing to do is to have the user manually call an async shutdown method rather than drop. This can be enforced at runtime by having a shutdown flag which is only set by the shutdown method and panicking in drop
if that flag is not set.
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'm afraid it's not backward compatible. I will change it to only calling block_on
when shutdown has not been called.
} | ||
|
||
unsafe impl Sync for SpawnTask {} |
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.
Could you add a comment for why this is safe (and why its required) please?
let (sr, rr) = futures::join!(send, receive); | ||
sr?; | ||
rr?; | ||
Ok(()) |
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.
Could this be sr.and(rr)
?
Ok(()) | ||
} | ||
|
||
fn main() { |
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.
Could use tokio::main
rather than async_main
src/call/mod.rs
Outdated
Ok(Async::NotReady) => {} | ||
if let Some(close_f) = &mut self.close_f { | ||
if let Poll::Ready(_) = Pin::new(close_f).poll(cx)? { | ||
// don't return immediately, there maybe pending data. |
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.
// don't return immediately, there maybe pending data. | |
// Don't return immediately, there may be pending data. |
Signed-off-by: Jay Lee <BusyJayLee@gmail.com>
PTAL |
Cargo.toml
Outdated
@@ -42,3 +42,6 @@ debug = true | |||
|
|||
[badges] | |||
travis-ci = { repository = "pingcap/grpc-rs" } | |||
|
|||
[patch.crates-io] | |||
grpcio-compiler = { path = "compiler", version = "0.5.0", default-features = false } |
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.
Missing \n
at end of file
proto/Cargo.toml
Outdated
@@ -28,5 +28,4 @@ lazy_static = { version = "1.3", optional = true } | |||
|
|||
[build-dependencies] | |||
protobuf-build = { version = "0.11", default-features = false } | |||
grpcio-compiler = { path = "../compiler", version = "0.5.0", default-features = false } | |||
walkdir = "2.2" | |||
walkdir = "2.2" |
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.
Missing \n
at end of file
Signed-off-by: Jay Lee <BusyJayLee@gmail.com>
Signed-off-by: Jay Lee <BusyJayLee@gmail.com>
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.
lgtm, thanks for the changes!
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.
LGTM
This reverts commit fd66ec7. Signed-off-by: Jay Lee <BusyJayLee@gmail.com>
Close #237.
Async trait doesn't seem to be supported yet. There is a solution, but I would rather wait sometime and check the community adoptions.