inconshreveable/muxado — reverse-engineered prompt
Reverse engineered prompt
Build me a Go library for stream multiplexing over one existing connection. I want to be able to take any io.ReadWriteCloser, usually a TCP connection, and split it into many independent two way byte streams so both sides can have lots of small requests in flight without opening more connections or writing custom async code.
Make the main session feel like a normal listener, and each stream feel like a normal connection, so it’s easy to plug into existing Go code. Include client and server session creation, opening outbound streams, accepting inbound streams, closing cleanly, basic error handling, flow control, tests, and simple examples using JSON request and response messages.
Also add optional helpers for typed streams, where a stream can be opened with a small type identifier, and a heartbeat wrapper that reports round trip latency and failures through callbacks. Keep it protocol agnostic and focused on small concurrent payloads, not big file transfer. Look up current Go docs if you need to, but keep the API simple and idiomatic.
Want more depth? Deep Reverse