``` suspend private fun _read(size: Int): ByteArra...
# coroutines
d
Copy code
suspend private fun _read(size: Int): ByteArray = suspendCoroutine { c ->
	val out = ByteArray(size)
	val buffer = ByteBuffer.wrap(out)
	sc.read(buffer, this, object : CompletionHandler<Int, AsyncClient> {
		override fun completed(result: Int, attachment: AsyncClient): Unit = run {
			if (result < 0) {
				c.resumeWithException(RuntimeException("EOF"))
			} else {
				c.resume(Arrays.copyOf(out, result))
			}
		}

		override fun failed(exc: Throwable, attachment: AsyncClient): Unit = run {
			c.resumeWithException(exc)
		}
	})
}