I’m using asyncio for the first time and find it a bit strange that asyncio.StreamReader.read
is async but asyncio.StreamWriter.write
is sync. Instead asyncio.StreamWriter.drain
is async.
Based on experience with streaming IO in other langs, I’d expect the concrete StreamWriter
implementation to notice when its internal buffer is full and flush as necessary. Since any write
could trigger that case, I’d expect write
to be async
and for drain
to be something you only call for latency/shutdown reasons. The current design seems to require StreamWriter
derived classes to buffer an arbitrary amount of data internally which goes against the goal of being for streaming, where you’re typically trying to stay in memory limits.
Why the asymmetry?