Replies: 1 comment 3 replies
-
Hey! Thank you for the detailed write up. The connect library also has a custom connect-es/packages/connect-node/src/node-readme.spec.ts Lines 269 to 279 in dc7d75a Can you give this a try and let us know if it works for you? |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
For APIs that stream in only one direction (stream request, single response or single request, stream response), the
AsyncIterator
abstraction works really well. I can feed a generator into the request, or consume the result withfor await
, and it's quite convenient.However, for bidirectional streaming APIs (stream request, stream response), this is not as convenient, since you need to provide an
AsyncIterator
for the request, and then consume theAsyncIterator
that's returned. This might be OK for simple "streaming-pipeline" cases where the request and response have nothing to do with each other. However, we make use of "conversational" bidi streaming APIs, where the client will stream a message to the server, then expect a corresponding response, and so on back and forth until both sides hang up. Effectively, each request and response message are paired up to form a little mini-RPC within the broader context of a single API call. Our case is supporting an interactive database transaction API, but you can imagine lots of use cases for this sort of API.We've managed to get things working by building a mildly complicated custom AsyncIterator class that can be passed as the request, which will then block on
next()
and allow request messages to be asynchronously enqueued. It allows us to effectively tie together the request and response streams so they can interact with each other, but it's a lot of tricky coordination code.For this type of API, something closer to how connect-go manages bidi streams would be much easier to deal with. In connect-go, bidi APIs return a
BidiStreamForClient
, which hasSend
andReceive
methods that can be used to send or receive a single message (along withCloseRequest
andCloseResponse
to hang up each end). This is much easier to use for these conversational APIs, since we now have a single handle that can be used to send a request, then await a response.Would folks be open to changing connect-es to use a similar API for bidi streams? Or to have this sort of API as an alternative option?
Beta Was this translation helpful? Give feedback.
All reactions