andylamax
05/22/2022, 6:53 PMdelay
what other functions actually suspends?
I am trying to get an example of a function that actually suspends (like delay), Not just marked as a suspend function and goes into IO operations like many I have seenephemient
05/22/2022, 6:59 PMandylamax
05/23/2022, 11:04 AMDALDEI
06/07/2022, 1:56 AMandylamax
06/07/2022, 8:25 AMephemient
06/08/2022, 12:07 AMDALDEI
06/09/2022, 1:43 PMephemient
06/09/2022, 1:53 PMThe current Linux POSIX AIO implementation is provided in user space by glibc. This has a number of limitations, most notably that maintaining multiple threads to perform I/O operations is expensive and scales poorly.so the only things worth special integration into kotlinx.coroutines are network streams and the like (IMO, because Linux servers and Android devices are by far the dominant use cases)
DALDEI
06/09/2022, 10:56 PMephemient
06/10/2022, 3:05 AMwithContext(<http://Dispatchers.IO|Dispatchers.IO>) { ... }
is about as good as you're going to get on Linux, no matter how you dress it up. you have to choose some dispatcher or executor for it, and even if you hide it behind another abstraction, you still have to be aware of its limits. (there is some potential in io_uring, but figuring out the ownership to bridge it to non-native code is not trivial, and for file I/O it simply spawns a kernel thread so you're still limited by that, just with a different constant)
socket I/O, on the other hand, has a lot more room where integration with coroutines could lead to better results. if it's built on NIO.2, then it'll happen to work for files too. but you shouldn't intentionally use it for files because the underlying implementation will use an unbounded executor that doesn't handle cancellationDALDEI
06/27/2022, 4:26 AMephemient
06/28/2022, 1:51 AMFlow<Byte>
, you should not as there is simply too much overhead that is necessary for other general purposes.
similarly, scalable async IO for files is simply impossible from the level at which Kotlin operates. sure, if you made it ergonomic to use NIO.2 channels in suspend, that would be great for network IO, but that doesn't get around the platform issues with file IO, even though it would technically "work".