Hi :wink: I need some help for understand one thi...
# coroutines
f
Hi 😉 I need some help for understand one thing, using:
Copy code
suspend fun <T> awaitEvent(block: (h: Handler<T>) -> Unit) : T {
    return suspendCancellableCoroutine { cont: CancellableContinuation<T> ->
        try {
            block.invoke(Handler { t ->
                cont.resume(t)
            })
        } catch(e: Exception) {
            cont.resumeWithException(e)
        }
    }
}
How can I use awaitEvent to listen to an handler of AsyncResult<String> and return MyObjectResult This is what I try to do:
Copy code
`
    override suspend fun get(userId: String): ContextInsideMessageBody? {
        return awaitEvent { handler ->
            val context = redis.get("peter/user/$userId/context", handler)
            if (context != null) {
                ContextInsideMessageBody().update(JsonObject(context)) as ContextInsideMessageBody
            } else {
                null
            }
        }
    }`
I want to return a different type from my awaitEvent { handler -> that the type the handler use