I’m running a SQS Message poller in my Spring Boot...
# coroutines
v
I’m running a SQS Message poller in my Spring Boot App and for every message I want it to be launched on a Coroutine something like this. How should I be bridging the gap, GlobalScope? Runblocking? Is there an example of this being done
Copy code
fun processMessages(){
    for (message in messages) {
        val foo = async {processMessage(message)
        val bar = foo.await()? // Is this how we await on a suspending function?
        when (bar) {
            is Outcome.Error -> {// don't delete message, log error}
            is Outcome.Success -> {deleteMessage()}
        }
     }
}

suspend fun processMessage(message): Outcome<Foo>

sealed class Outcome<out T : Any> {

    data class Error(val message: String, val cause: Exception? = null) : Outcome<Nothing>()

    data class Success<out T : Any>(val value: T) : Outcome<T>()
}
p
Ideally create your own scope that's aligned with the lifecycle of your listener bean and launch in that?
t