https://kotlinlang.org logo
d

Deactivated User

12/24/2016, 5:04 PM
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) {
				println("___read.completed.Resume: EOF")
				c.resumeWithException(RuntimeException("EOF"))
			} else {
				println("___read.completed..Resume: $out")
				c.resume(Arrays.copyOf(out, result))
			}
		}

		override fun failed(exc: Throwable, attachment: AsyncClient): Unit = run {
			println("___read.failed.Resume: $exc")
			c.resumeWithException(exc)
		}
	})
}
no traces at all