Almost. Two issues I can think of: 1. After each pump completes, you probably want to call shutdownWrite() to propagate the EOF. 2. `joinPromises()` always waits for all promises to resolve. I've often found that this turns out to be the wrong behavior when one of the joined promises throws an exception. Usually you want the other tasks canceled in that case. I think that might be the case here -- if you get an I/O error in one direction, you probably want to kill the whole stream. Then again, probably that'll happen anyway in most cases. (Whereas, EOF is not an error, so you do want to wait for the other promise in that case.)
On another note, a warning: I'm likely to change the AsyncOutputStream interface significantly in the future, in order to replace `shutdownWrite()` with something that returns a promise, and to make it so that if you don't explicitly shut down a stream, then it's treated as an error. Currently, AsyncOutputStream's destructor implicitly sends a clean EOF, but that's the wrong thing to do when the sender terminated prematurely due to an exception. So, your code will need some updating when that happens. -Kenton On Sun, Jul 5, 2020 at 8:13 PM Vitali Lovich <vlov...@gmail.com> wrote: > I was wondering what would be the best way to bridge 2 kj::AsyncIoStreams > to each other (read to write/write to read) so that they act as > pass-through? I'm assuming something like: > > auto pumped = kj::ArrayBuilder<kj::Promise<void>>(2); > pumped.add(stream1.pumpTo(stream2).ignoreResult()); > pumped.add(stream2.pumpTo(stream1).ignoreResult()); > return kj::joinPromises(pumped.finish()).ignoreResult(); > > Thanks, > Vitali > > -- > You received this message because you are subscribed to the Google Groups > "Cap'n Proto" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to capnproto+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/capnproto/CAF8PYMh%3DKr9Yzmz9on4Cxprb0irNOGpV0MUtBxdGitbOgkjiEg%40mail.gmail.com > <https://groups.google.com/d/msgid/capnproto/CAF8PYMh%3DKr9Yzmz9on4Cxprb0irNOGpV0MUtBxdGitbOgkjiEg%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "Cap'n Proto" group. To unsubscribe from this group and stop receiving emails from it, send an email to capnproto+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/capnproto/CAJouXQnQT2EeTcZt5XrJU%3Djc%3D%3DHk5mO497d79pVA-Q-F1%2BKiGA%40mail.gmail.com.