Hello everyone, starting a new service in Fargate....
# coroutines
h
Hello everyone, starting a new service in Fargate. The idea is to have a Netty4 server (custom internal construct that I can't really avoid, either this or a custom Tomcat). I'm currently a bit lost on how I should go about starting the coroutines, especially since the actual operations are obtained via Guice. Effectively I have
Copy code
fun main(args: Array<String>) {
    val server = NETTY_SERVER

    Runtime.getRuntime().addShutdownHook(
        Thread {
            close("Netty4 Server") { server.cancel() }
        },
    )

    server.await()
}
and then through the magic of Guice, I get to something like this
Copy code
@Service(APPLICATION_NAME)
class EchoActivity : Activity() {

    @Operation("Echo")
    fun echo(input: EchoInput): EchoOutput {
        return EchoOutput
            .builder()
            .withString(input.string)
            .build()
    }
}
A few of the alternatives I found were: 1. Ensuring
main
is
runBlocking(Dispachers.Default)
-> this can be done but it doesn't eventually impact the EchoActivity, as it isn't called directly from the
main
function. 2. Creating a global variable like
val COROUTINE_SCOPE = CoroutineScope(Dispatchers.Default + SupervisorJob())
with a shutdown hook next to the server and then just use it everywhere to manage all the requests Does any of this track with you? I've been doing some tests (basically spamming this Echo) and I'm not getting what I expect - a lot of single threaded/single coroutine usage