I was thinking again about design for suspended in...
# io
a
I was thinking again about design for suspended input (it seems that suspended ouptut does not make any sense since it fire-and-forget anyway). Duplicating all functionality like
writeInt
in a suspended manner seems to be troublesome and does not really help since we would not be able to reuse
Input
methods for supposed
SuspendedInput
. It seems that is better to have some kind of
ByteSource
class which has single method with signature
suspend fun awaitBytes(size: Int, block: Input.()->R):R
. The idea is that we suspend caller untill
size
of bytes is fetched or at least guaranteed to be fetched in non-blocking manner. After that we can work with those bytes with regular
Input
-based way. Working with packages of unknown size could be a bit cumbersome, but I do not thing there are lot of cases, where we really need it.