Extensions for java.nio.channels.AsynchronousSocketChannel

aConnect

suspend fun AsynchronousSocketChannel.aConnect(
    socketAddress: SocketAddress
): Unit

Performs AsynchronousSocketChannel.connect without blocking a thread and resumes when asynchronous operation completes. This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while this suspending function is waiting, this function closes the underlying channel and immediately resumes with CancellationException.

aRead

suspend fun AsynchronousSocketChannel.aRead(
    buf: ByteBuffer,
    timeout: Long = 0L,
    timeUnit: TimeUnit = TimeUnit.MILLISECONDS
): Int

Performs AsynchronousSocketChannel.read without blocking a thread and resumes when asynchronous operation completes. This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while this suspending function is waiting, this function closes the underlying channel and immediately resumes with CancellationException.

aWrite

suspend fun AsynchronousSocketChannel.aWrite(
    buf: ByteBuffer,
    timeout: Long = 0L,
    timeUnit: TimeUnit = TimeUnit.MILLISECONDS
): Int

Performs AsynchronousSocketChannel.write without blocking a thread and resumes when asynchronous operation completes. This suspending function is cancellable. If the Job of the current coroutine is cancelled or completed while this suspending function is waiting, this function closes the underlying channel and immediately resumes with CancellationException.