Skip to content
/ knio2 Public

Kotlinx coroutines extensions for Java NIO.2

License

Notifications You must be signed in to change notification settings

agcom/knio2

Repository files navigation

KNIO2

Maven Central latest version badge Awesome Kotlin badge License badge

Just some Kotlinx coroutines extensions for java.nio.channels.Asynchronous* classes.

Setup

Published to the Maven Central repository.

Gradle snippet,

repositories {
    mavenCentral()
}

dependencies {
    implementation "io.github.agcom:knio2:0.4.1"
}

Components

  • 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
      }

Contribution

I add what I need. Make sure you do it too 😃.

Status

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.

About

Kotlinx coroutines extensions for Java NIO.2

Topics

Resources

License

Stars

Watchers

Forks

Languages