mikeal / znode

Bi-directional RPC through any stream.
206 stars 13 forks source link

Feature Request: return Streams via rpc #5

Closed kumavis closed 6 years ago

kumavis commented 6 years ago

would be really neat to be able to return a stream as the result of an rpc call

kumavis commented 6 years ago

my usecase is to be able to make a request a stream results back

mikeal commented 6 years ago

I've thought about this a lot and I don't think it's a good idea. You could do it, you could also do something similar with async iterators, but they both suffer from the same problem which is that you're incurring a round trip to request each chunk.

If you're going to do this, it's actually a lot better to use a stream multiplexer like https://www.npmjs.com/package/multiplex and then just use one of the sub-streams for the RPC channel. You could even use znode to signal sending the new stream sub-stream.