Extensions for java.nio.channels.AsynchronousFileChannel

aLock

suspend fun AsynchronousFileChannel.aLock(): FileLock
suspend fun AsynchronousFileChannel.aLock(
    position: Long,
    size: Long,
    shared: Boolean
): FileLock

Performs AsynchronousFileChannel.lock 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 AsynchronousFileChannel.aRead(
    buf: ByteBuffer,
    position: Long
): Int

Performs AsynchronousFileChannel.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 AsynchronousFileChannel.aWrite(
    buf: ByteBuffer,
    position: Long
): Int

Performs AsynchronousFileChannel.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.