Just some Kotlinx coroutines extensions for java.nio.channels.Asynchronous*
classes.
Published to the Maven Central repository.
Gradle snippet,
repositories {
mavenCentral()
}
dependencies {
implementation "io.github.agcom:knio2:0.4.1"
}
-
Suspending extension functions for following classes,
AsynchronousByteChannel
AsynchronousSocketChannel
AsynchronousFileChannel
AsynchronousServerSocketChannel
The functions are named after their original name plus
await
suffix.import io.github.agcom.knio2.* import java.nio.ByteBuffer import java.nio.channels.AsynchronousSocketChannel suspend fun main() { val socket: AsynchronousSocketChannel = TODO().apply { connectAwait(TODO()) // connectAwait } ByteBuffer.allocate(TODO()).let { socket.readAwait(it) // readAwait } socket.writeAwait(Charsets.US_ASCII.encode("Hello world")) // writeAwait }
I add what I need. Make sure you do it too ๐.
If you only want Kotlinx coroutines IO, prefer its native libraries instead of Java ports. You can find them on Awesome Kotlin.
This is a temporary project and may deprecate in favor of better asynchronous IO solutions with Kotlinx coroutines. For example, the Kotlinx IO, which is kinda in development now.