You can check out my "example" in issue 2247 <https://github.com/grpc/grpc-java/issues/2247#issuecomment-245949881>.
On Fri, Oct 28, 2016 at 8:32 AM, Matt Mitchell <[email protected]> wrote: > So if I'm emitting a stream from my server, should I be checking isReady() > before each onNext() call? > You should check it occasionally; it doesn't have to be done for every message. I'd suggest checking it _after_ onNext(); if you already have a message, go ahead and send it; just delay creating more messages. Java's flow control is advisory: gRPC tells you when it is no longer productive to queue more messages and you stop when convenient. But anything you queue will be queued, so you have to be aware of how much memory you may be wasting. I'm currently reading an InputStream and chunking out to the response, so > really what I'm doing is "waiting" (while/sleep) for isReady to be true on > each read from the InputStream. > That's fair, although we provide a callback like I showed in the link above. Again, I'd suggest calling onNext() first and then if isReady() is false, just delay calling read(). I really wish there were a way to do a blocking stream write/read so the > backpressure handling was driven by the client reads. > Which would be a blocking API, which Stream Observer is not. We would like to have blocking APIs server-side, but it wasn't clear what the "idiomatic" Java API would be. Streaming can also be hard (especially bi-di) because it is easy for you to deadlock if you aren't careful. Having to wait/sleep or react to asynchronous messages in the server (for > example, client could send a "pause" message, server could "sleep") feels > complicated and brittle. > The setOnReadyHandler makes it reasonable. It is still an async API, which has its advantages and downfalls. -- You received this message because you are subscribed to the Google Groups "grpc.io" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/grpc-io. To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/CA%2B4M1oO5qDMKgPUQeQF56SoqzmTuoQ2wmdP06kC076Jca7JZsw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
