Comments (5)
Yes, that did it, thank you @overvenus! If anyone else gets stuck on this, this is what I ended up with:
fn transaction(&self, ctx: grpcio::RpcContext, stream: grpcio::RequestStream<request::TransactionRequest>, mut sink: grpcio::DuplexSink<response::TransactionResponse>) {
let datastore = self.datastore.clone();
let trans = datastore.transaction().unwrap();
for result in stream.wait() {
let response = match result {
Ok(request) => build_response(&trans, &request).unwrap_or_else(|err| build_error_response(&err)),
Err(err) => build_error_response(&err)
};
sink = sink.send(response).wait().unwrap();
}
}
(With the usual caveat that unwrap
is only used here to make the example more terse.)
from grpc-rs.
seem you can use future wait to act as a sync call.
from grpc-rs.
Here's the best I could chalk up with that in mind:
fn transaction(&self, ctx: grpcio::RpcContext, stream: grpcio::RequestStream<request::TransactionRequest>, sink: grpcio::DuplexSink<response::TransactionResponse>) {
let datastore = self.datastore.clone();
let trans = datastore.transaction().unwrap();
for result in stream.wait() {
match result {
Ok(request) => {
let response = match build_response(&trans, request) {
Ok(response) => response,
Err(err) => build_error_response(&err)
};
sink.send((response, grpcio::WriteFlags::default()));
}
Err(err) => {
let response = build_error_response(&err);
sink.send((response, grpcio::WriteFlags::default()));
}
}
}
}
This doesn't work because grpcio::DuplexSink::send
consumes self
. Also, I'm guessing grpcio doesn't setup a thread per request, so wouldn't this bottleneck request anyways?
(For context, datastore.transaction()
wraps a postgresql transaction, which is not Sync
.)
from grpc-rs.
/cc @BusyJay
from grpc-rs.
Hi @ysimonson
Is there a way to use grpc-rs without futures, i.e. just synchronously?
Yes, just as @siddontang s suggestion.
I ask because I'm dealing with
!Sync
types, and it's not clear to me whether it's possible to use them withgrpcio::RpcContext::spawn
.
Yes, it can, e.g.,
diff --git a/tests/cases/alarm.rs b/tests/cases/alarm.rs
index 53d8009..01ed67e 100644
--- a/tests/cases/alarm.rs
+++ b/tests/cases/alarm.rs
@@ -27,6 +27,7 @@ struct GreeterService {
impl Greeter for GreeterService {
fn say_hello(&self, ctx: RpcContext, mut req: HelloRequest, sink: UnarySink<HelloReply>) {
+ let mut c = ::std::cell::Cell::new(1); // <- It's `!Sync`.
let (tx, rx) = oneshot::channel();
let tx_lock = self.tx.clone();
let name = req.take_name();
@@ -38,6 +39,7 @@ impl Greeter for GreeterService {
.and_then(move |(greet, _)| {
let mut resp = HelloReply::new();
resp.set_message(format!("{} {}", greet, name));
+ *c.get_mut() += 1;
sink.success(resp)
.map_err(|e| panic!("failed to reply {:?}", e))
});
You can apply this diff and cargo test --all
.
This doesn't work because
grpcio::DuplexSink::send
consumesself
.
It does consumes self
, but also returns Self
. I think you can:
let sink = sink.send(...).wait().unwrap();
from grpc-rs.
Related Issues (20)
- Why returns `Failed to pick subchannel` when sent a backupRequest HOT 1
- grpcio-sys libabsl_bad_optional_access.a: file too small to be an archive HOT 6
- Support code generation for proto definitions utilizing experimental features HOT 1
- failed to build in mac HOT 6
- grpcio-sys-0.8.1 build error HOT 2
- grpcio v0.12.1 failed to build HOT 13
- grpcio-sys-0.12.1+1.46.5-patched compile error on latest `clang` HOT 3
- TiKV runs into Handshake failed with fatal error SSL_ERROR_SSL. HOT 2
- Failed to build on windows
- 0.12.1+1.56.2-patched failed to link systemd HOT 2
- Examples not compiling HOT 2
- add support to measure message delivery's time from the StreamingCallSink's
- Cmake error when trying to use grpcio with 0.13.0 HOT 2
- Don't know how to use TLS. HOT 2
- Bump prost to `0.12` HOT 1
- MetadataBuilder should implement Clone
- observability: improve the observability for every cq running task
- performance: more cost on CPU when upgrading to v0.13.0 HOT 1
- Unable to compile w/ prost-codec, missing proto files in grpcio-sys directory? HOT 3
- Dependency `ansi_term` is Unmaintained HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grpc-rs.