Last active
April 25, 2023 01:08
-
-
Save mrenouf/41e7d22b2fe93c6d43a989a787087978 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
suspend fun AsynchronousByteChannel.readInto(buffer: ByteBuffer): Int = suspendCancellableCoroutine { | |
read(buffer, null, object : CompletionHandler<Int, Any?> { | |
override fun completed(result: Int, attachment: Any?) { it.resume(result) } | |
override fun failed(exc: Throwable, attachment: Any?) = it.resumeWithException(exc) | |
}) | |
} | |
suspend fun AsynchronousByteChannel.writeFrom(buffer: ByteBuffer): Int = suspendCancellableCoroutine { | |
write(buffer, null, object : CompletionHandler<Int, Any?> { | |
override fun completed(result: Int, attachment: Any?) = it.resume(result) | |
override fun failed(exc: Throwable, attachment: Any?) = it.resumeWithException(exc) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment