From 29ac56fe1e1e310ce346352d6ad2daca1b40ebcf Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 2 Jan 2021 13:22:47 +0000 Subject: [PATCH] Replace flushRequests() with channelReadComplete() Signed-off-by: Graham --- .../archive/cache/Js5ChannelHandler.kt | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/archive/src/main/kotlin/org/openrs2/archive/cache/Js5ChannelHandler.kt b/archive/src/main/kotlin/org/openrs2/archive/cache/Js5ChannelHandler.kt index b0d9afa6f2..767dc4ed98 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/cache/Js5ChannelHandler.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/cache/Js5ChannelHandler.kt @@ -56,6 +56,17 @@ public class Js5ChannelHandler( } } + override fun channelReadComplete(ctx: ChannelHandlerContext) { + while (inFlightRequests.size < maxInFlightRequests) { + val request = pendingRequests.removeFirstOrNull() ?: break + inFlightRequests += request + ctx.write(request, ctx.voidPromise()) + } + + ctx.flush() + ctx.read() + } + override fun exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable) { releaseGroups() ctx.close() @@ -75,7 +86,6 @@ public class Js5ChannelHandler( val request = Js5Request.Group(false, Js5Archive.ARCHIVESET, Js5Archive.ARCHIVESET) pendingRequests += request - flushRequests(ctx) } private fun handleClientOutOfDate(ctx: ChannelHandlerContext) { @@ -118,8 +128,6 @@ public class Js5ChannelHandler( if (complete) { ctx.close() continuation.resume(Unit) - } else { - flushRequests(ctx) } } @@ -158,17 +166,6 @@ public class Js5ChannelHandler( } } - private fun flushRequests(ctx: ChannelHandlerContext) { - while (inFlightRequests.size < maxInFlightRequests) { - val request = pendingRequests.removeFirstOrNull() ?: break - inFlightRequests += request - ctx.write(request, ctx.voidPromise()) - } - - ctx.flush() - ctx.read() - } - private fun releaseGroups() { groups.forEach(CacheImporter.Group::release) groups.clear()