Add IO::Stapled#6017
Conversation
| end | ||
| end | ||
|
|
||
| {% unless flag?(:win32) %} |
There was a problem hiding this comment.
IO.pipe will work on windows after we merge #5623, so might as well not have this check
|
Added |
| end | ||
| end | ||
|
|
||
| # Creates a pair of bidirectional pipe endpints connected with each other |
b472703 to
c3a96dd
Compare
| # This class staples together two unidirectional `IO`s to form a single, | ||
| # bidirectional `IO`. | ||
| # | ||
| # Example (loopback): |
There was a problem hiding this comment.
I would use another example, maybe using two IO::Memory. When I first saw this I thought "why not use IO.pipe directly?".
|
Is there any use case other than "mocking sockets in specs"? |
|
Is there any use to I'd be interested in other usages, but I think this is worth it just for the speccing. |
|
@ysbaddaden You could for example wrap the standard streams with HTTP or any other protocol that expects read and write on the same IO ;) |
|
At least I can appreciate the idea of |
|
@ysbaddaden I think the idea is to use it for specs, to stub a socket. But if we are going to do that, maybe |
|
Yes, the main purpose of this is obviously mocking socket connections, but it can also be generally useful for multiplexing two unidirectional read/write streams in one IO. Limiting to |
|
Hm, maybe wrapping two pipes is a good use case... |
* Add IO::Stapled * fixup! Add IO::Stapled * fixup! Add IO::Stapled
Adds
IO::Stapledclass which staples together two unidirectionalIOs to form a single bidirectionalIO. It basically delegates all read methods toreaderand all write methods towriter.This class is an extension to unidirectional IOs (like
IO::Memory,IO.pipe) when you need true bidirectional IOs, for example as a replacement for socket streams.This is particularly useful for speccing code that would normally work with a socket. You don't need to create an actual socket but can just staple together two
IO::Memory.